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;

}

相关推荐
秦.赢渠梁43 分钟前
各种通信(三):GPS模块数据解析
c语言
量子炒饭大师3 小时前
收集飞花令碎片——C语言字符函数与字符串函数
c语言·开发语言
web安全工具库5 小时前
Makefile 模式规则精讲:从 %.o: %.c 到静态模式规则的终极自动化
linux·运维·c语言·开发语言·数据库·自动化
earthzhang20218 小时前
【1028】字符菱形
c语言·开发语言·数据结构·c++·算法·青少年编程
承渊政道12 小时前
动态内存管理
c语言·c++·经验分享·c#·visual studio
Narcissiffo13 小时前
【C语言】str系列函数
c语言·开发语言
hqyjzsb14 小时前
2025年市场岗位能力重构与跨领域转型路径分析
c语言·人工智能·信息可视化·重构·媒体·改行学it·caie
小莞尔14 小时前
【51单片机】【protues仿真】基于51单片机智能窗帘系统
c语言·stm32·单片机·嵌入式硬件·物联网·51单片机
懒羊羊不懒@14 小时前
Java基础语法—最小单位、及注释
java·c语言·开发语言·数据结构·学习·算法
SundayBear15 小时前
嵌入式进阶:C语言内联汇编
c语言·开发语言·汇编