对于一个项目,我希望在一个函数中创建一个空链接列表,然后在另一个函数中使用该链接列表向其中添加项目。目前,这是我的空链表代码:
typedef struct node_t {
int value;
int priority;
struct node_t *next;
}node;
typedef struct priorty_linked_list {
struct name *head;
int current_size;
int max_size;
}priority_list;
typedef node *Node;
typedef priority_list *List;
我们的老师给了我们上面的代码,所以应该没有什么问题。接下来我从创建函数开始:
void create(int max_terms) {
node *head = NULL;
node *next = NULL;
List *current_size = 0;
List *max_size = max_terms;
max_size = (List*)malloc(sizeof(List));
printf("The maximum size for the list is %d",max_terms);
}
我假设下一个函数要求我使用 create 函数的返回函数,但我不确定如何使用。 add 函数应该将上面创建的队列作为参数,如果我之前由于内存分配而没有创建队列,则该函数将无法工作。
任何有关我上述代码的提示或建议将不胜感激!
谢谢:)
最佳答案
我猜想在 priorty_linked_list
的定义中,您想写:
struct node *head;
而不是:
struct name *head;
This site has a great explanation以及可以借鉴的不错的实现。网络中有数千个与您必须实现的示例非常相似的示例。不要害怕用 Google 搜索它。
关于c - 将项目添加到空链表 C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27754669/