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;

}

相关推荐
无相求码7 小时前
【C语言】字符串的本质是什么,为什么 strlen 会读到野内存
c语言·开发语言
LuminousCPP9 小时前
C 语言集中实践全记录:顺序表 + 单链表原理实现与通讯录项目实战【附可运行源码】
c语言·开发语言·数据结构·经验分享·笔记
SuperByteMaster9 小时前
__set_MSP 和__set_MSPLIM 接口区别
c语言
CS创新实验室11 小时前
NumPy数组的C风格和Fortran风格
c语言·开发语言·numpy
LuminousCPP12 小时前
单链表专题(应用篇):三道经典题吃透删除、反转与快慢指针
c语言·数据结构·笔记
薄情书生13 小时前
基于51单片机的电子钟设计(LCD12864显示 + DS1302)
c语言·51单片机·protues
半条-咸鱼13 小时前
【FreeRTOS】核心原理与实战速查手册
c语言·操作系统·rtos
白帽小阳13 小时前
Typora插件开发指南:打造专属IDE式写作环境
c语言·网络·python·网络安全·github·pygame·护网行动
ysu_03141 天前
06 | 200个单元测试C项目也能TDD
c语言·单元测试·tdd
烟锁池塘柳01 天前
【C/C++】解决C++控制台输出中文乱码问题
c语言·开发语言·c++