将项添加到空链表C.

时间:2015-01-03 12:07:00

标签: c function linked-list return

对于项目,我希望在一个函数中创建一个空链表,然后在另一个函数中使用该链表来向其中添加项。目前这是我的空链表的代码:

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;

我们的导师给了我们上面的代码,所以不应该有任何问题。接下来我开始使用create:

功能
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函数的return函数,但我不确定如何。 add函数应该将上面创建的队列作为参数,如果由于内存分配而没有创建队列,则无法工作。

我非常感谢您对上述代码的任何提示或建议!

谢谢:)

1 个答案:

答案 0 :(得分:1)

我想在priorty_linked_list的定义中猜测,你想写一下:

struct node *head;

而不是:

struct name *head;

This site has a great explanation和可用于参考的体面实施。 Web上有成千上万的例子,与你必须实现的非常类似。不要害怕谷歌。