c - 搜索到链表
问题描述
struct Players
{
int pid; /*Player's identifier*/
int is_alien; /*Alien flag*/
int evidence; /*Amount of evidence*/
struct Players *prev; /*Pointer to the previous node*/
struct Players *next; /*Pointer to the next node*/
struct Tasks *tasks_head; /*Pointer to the head of player's task list*/
struct Tasks *tasks_sentinel; /*Pointer to the sentinel of player's task list*/
};
/**
* Structure defining a node of the airplane linked list
*/
struct Tasks
{
int tid; /*Task's identifier*/
int difficulty; /*Task's difficulty*/
struct Tasks *next; /*Pointer to the next node*/
};
struct Player *players_head; //Global pointer
所以我有这些。我需要搜索玩家的任务。我做了
struct Players *player=players_head;
struct Tasks *tasks,*test;
test=(struct Tasks*)malloc(sizeof(struct Tasks));
if(player == NULL) {
return 0;
}
while(player != NULL) {
test=player->tasks_head;
//some other code..
我的问题是为什么test=player->task_head
为空。问题出在player->tasks_head
我也试过 objtasks = player->tasks_head
有什么帮助吗?谢谢
解决方案
恐怕您从未将 tasks_head 指针设置为指向列表的头部,是吗?
它应该在列表构造函数中第一次完成,并且每次将项目添加到列表的头部时,它都应该更改为更新的项目。
希望它有所帮助!
推荐阅读
- powershell - 在 PowerShell 脚本中从 Sqlcmd 获取错误
- c# - 是否可以通过其他一些 Windows 服务或相同的 Windows 服务启动/停止 Windows 服务?
- javascript - 我正在为我的学校项目创建一个样机电影网站。我遇到了一些与“选择”表单和 JavaScript 代码相关的问题
- ruby-on-rails - 如果未上传载波图像,则添加默认图像
- c++ - 应用程序在 Windows 10 上的 boost::filesystem::exist 和 CoInitializeSecurity 调用上自行启动
- selenium - 无法从网站 (goibibo.com) 中选择城市名称
- ionic-framework - 在 Ionic 1 应用程序中创建页面的应用程序快捷方式
- android - 如何在 Retrofit 中使用 execute
- c++ - 如何使用变体和使用处理复杂的标头递归
- bash - 如何在 ssh 脚本中获取嵌套的 sftp 以等待密码提示