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;

}

相关推荐
Navigator_Z3 小时前
LeetCode //C - 1187. Make Array Strictly Increasing
c语言·算法·leetcode
别动我齐刘海4 小时前
“三层同步审计”判定掉帧缺失
c语言·c++·人工智能·深度学习·学习·机器学习·机器人
十月的皮皮4 小时前
STM32从零到量产开发:四路继电器工业控制模块开发 -上位机主窗口设计说明
c语言·stm32·单片机·stm32cubemx
wuyk5555 小时前
第1章:无刷电机核心原理与运行机制
c语言·开发语言·stm32·单片机·嵌入式硬件·机器学习
坚持编程的菜鸟5 小时前
模拟实现strncat
c语言·算法·模拟实现strncat
Hhy_11075 小时前
【从零开始学数据结构 ⑥】:二叉树之堆——打破规则的优先队列
c语言·开发语言·数据结构·学习·visual studio
0x3F(小茶)6 小时前
FreeRTOS 系统配置
c语言·单片机·mcu
wengqidaifeng6 小时前
2026 年电赛(TI 杯)H 题:完整测评流程、失败案例复盘、比赛策略与开源交付
c语言·单片机·嵌入式硬件
ysu_03146 小时前
【创作128天纪念】从新手村踏上征途
c语言
0x3F(小茶)6 小时前
FreeRTOS 任务相关 API 函数
c语言·arm开发·单片机