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;

}

相关推荐
小刘爱玩单片机5 分钟前
【stm32简单外设篇】- 测速传感器模块(光电)
c语言·stm32·单片机·嵌入式硬件
hateregiste9 分钟前
嵌入式软件开发中常见知识点问答集锦!
c语言·单片机·嵌入式软件
极客小张12 分钟前
基于STM32的智能水质监测与远程预警系统设计与实现
c语言·python·stm32·单片机·嵌入式硬件·物联网
Once_day12 分钟前
GCC编译(7)链接脚本LinkerScripts
c语言·c++·编译和链接·程序员自我修养
小刘爱玩单片机30 分钟前
【stm32简单外设篇】- KY-025 干簧管(磁控)模块
c语言·stm32·单片机·嵌入式硬件
小付同学呀1 小时前
C语言学习(六)——运算符
c语言·数据结构·学习
会员果汁1 小时前
二分搜索-C
c语言·算法
智者知已应修善业1 小时前
【查找指定字符串首位置与数量不区分大小写完整匹配】2025-5-3
c语言·c++·经验分享·笔记·算法
老师用之于民1 小时前
【DAY25】线程与进程通信:共享内存、同步机制及实现方案
linux·c语言·ubuntu·visual studio code