2024.02.05

复习单向,双向链表,并且实现两种链表的增加和删除功能。

单链表头插

Linklist insert_head(datatype element,Linklist head) {

//创建新节点

Linklist s=create_node();

if(NULL==s) return head;

s->data=element;

//1,判断链表为空

if(NULL==head)

{

head=s;

} else //链表不为空

{

s->next=head; head=s;

}

return head;

}

单链表头删

Linklist delete_head(Linklist head)

{

//1,判断链表为空

if(NULL==head)

{

return head;

} else //链表存在1个或多个节点

{

Linklist del=head;

head=head->next;

free(del);

del=NULL;

}

return head;

}

双向链表头插

Doublelink double_insert_head(datatype element,Doublelink head)

{

//创建新节点s

Doublelink s=create_node();

if(s==NULL) return head;

strcpy(s->data,element);

//1.判断链表为空

if(NULL ==head)

head=s;

//2.存在多个节点>=1

else {

s->next=head;

head->priv=s;

head=s;

}

return head;

}

双向链表尾删

Doublelink delete_rear(Doublelink head)

{

//1,判断链表为空

if(NULL ==head)

return head;

//2,只有一个节点

if(head->next==NULL)

{

free(head);

head=NULL;

} else //>=2

{

//找到最后一个节点

Doublelink p=head;

while(p->next!=NULL)

{

p=p->next;

} p->priv->next=NULL;

free(p);

p=NULL;

}

return head;

}

相关推荐
三品吉他手会点灯3 小时前
C语言学习笔记 - 35.数据类型 - printf函数的非输出控制符与格式优化
c语言·开发语言·笔记·学习
Ghost Face...4 小时前
U-Boot SPL阶段与主阶段深度解析:从ROM到Kernel的完整引导之旅(ARMv8)
c语言
三品吉他手会点灯5 小时前
C语言学习笔记 - 33.数据类型 - printf函数的详细用法
c语言·开发语言·笔记·学习·算法
t-think6 小时前
深入理解指针(2)
c语言·开发语言
我不是懒洋洋7 小时前
从零开始实现一个简单的神经网络:C语言版
c语言
百万老师8 小时前
自然语言编程时代,如何零基础学习掌握嵌入式编程
c语言·单片机·嵌入式硬件·学习·ai全流程闭环开发
淞綰8 小时前
c语言的练习-字符串的练习-寻找最长连续字符以及出现次数
c语言·数据结构·学习·算法·c语言的练习
三品吉他手会点灯11 小时前
C语言学习笔记 - 36.数据类型 - 为什么需要输出控制符
c语言·开发语言·笔记·学习
阳光九叶草LXGZXJ11 小时前
自制数据库迁移工具-C版-07-HappySunshineV1.6-(支持PG、达梦、Gbase8a)
linux·c语言·开发语言·数据库·学习·postgresql
星恒随风11 小时前
从0开始的操作系统学习之路(2)
c语言·笔记·学习