初始化头节点
#include <stdio.h>
typedef int ElemType;
typedef struct node
{
ElemType data;
struct node* next;
}Node;
//初始化头节点
Node* initlist()
{
//首先创建一个头节点
Node* head = (Node*)malloc(sizeof(Node));
//赋值
head->data = 0;
head->next = NULL;
return head;
}
使用malloc函数,实现内存分配,定义一个头节点head,将数据0赋给head的数据域,指针域则指向下一个节点,目前没有为NULL