更多资料请点击:我的目录
本篇仅用于记录自己所学知识及应用,代码仍可优化,仅供参考,如果发现有错误的地方,尽管留言于我,谢谢!
链表结构体和函数模板:
//结构体:
struct node
{
int data;
struct node *next;
};
//初始化一个带头节点的空链表
struct node *list()//初始化一个带头节点的空链表
{
struct node *head = malloc(sizeof(struct node));
if(head != NULL)
{
head->next = NULL;
}
return head;
}
//创建一个新的节点
struct node *new_list(int data)//创建一个新的节点
{
struct node *new = malloc(sizeof(struct node));
if(new != NULL)
{
new->data = data; //赋值
new->next = NULL;
}
return new;
}
//输出链表所有节点
void show_list(struct node *head)//输出链表所有节点
{
while(head->next != NULL)
{
head = head->next;
printf("%d\t",head->data);
}
printf("\n");
}
//输出链表所有节点
void show_list(struct node *head)//输出链表所有节点
{
while(head->next != NULL)
{
head = head->next;
printf("%d\t",head->data);
}
printf("\n");
}
更多资料请点击:我的目录