这是C编程语言中链接列表的代码。如何在C中使用结构?
#include <stdio.h> /* For printf */
#include <stdlib.h> /* For malloc */
typedef struct node {
int data;
struct node *next; /* Pointer to next element in list */
} LLIST;
LLIST *list_add(LLIST **p, int i);
void list_remove(LLIST **p);
LLIST **list_search(LLIST **n, int i);
void list_print(LLIST *n);
该代码没有完成,但我认为这足以满足我的问题。这里在结构节点“LLIST”的末尾使用了,它也被用作功能list_add
原型中的返回类型。到底是怎么回事?
从技术上讲,你应该为每个项目做一个'malloc'在列表中,因为它不是一个严格的列表,而是一个带有指向列表中下一项的指针('* next')的结构。因此,您在创建每个列表项时都会执行单独的malloc。 – wizzwizz4 2016-04-09 14:45:15