刚好像学习下数据结构,所以就找了些资料写了个简单单链表,有错误的地方还望大神指正。
链表是物理上存储不连续的数据结构,通过链表节点关联下一个链表节点,它与数组不同,数组存储在物理上是连续的。
链表节点包含:节点数据域和节点后继指针域(图分析后面补上)
#include<stdio.h>
#include<malloc.h>
#include <errno.h>
//创建节点数据结构
typedef struct List
{
int date;
struct List *next;
}Node;
//初始化链表头结点
Node* Init_head()
{
Node*head=(Node*)malloc(sizeof(Node));
if(NULL==head)
{
perror("malloc\n");
return NULL;
}
head->next=NULL;
printf("Init_head succed!\n");
printf("#################\n");
return head;
}
//增加节点
Node *Add_List_Node(Node*head,int date)
{
Node*phead,*new_node;
phead=head;
if(NULL==phead)
{
return NULL;
}
else
{
while(phead->next!=NULL)
{
phead=phead->next;
}
if(NULL!=(new_node=(Node*)malloc(sizeof(Node))))
{
new_node->date