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;

}

相关推荐
学无止境\n1 分钟前
[C语言]指针和数组
c语言·数据结构·算法
jyan_敬言1 小时前
【Linux】Linux命令与操作详解(一)文件管理(文件命令)、用户与用户组管理(创建、删除用户/组)
linux·运维·服务器·c语言·开发语言·汇编·c++
bcdaren2 小时前
《Windows PE》4.2 绑定导入表
c语言·汇编·windows·pe
jmlinux2 小时前
环形缓冲区(Ring Buffer)在STM32 HAL库中的应用:防止按键丢失
c语言·stm32·单片机·嵌入式硬件
TU^4 小时前
C语言习题~day16
c语言·前端·算法
DdddJMs__1354 小时前
C语言 | Leetcode C语言题解之第461题汉明距离
c语言·leetcode·题解
中杯可乐多加冰4 小时前
【AI驱动TDSQL-C Serverless数据库技术实战】 AI电商数据分析系统——探索Text2SQL下AI驱动代码进行实际业务
c语言·人工智能·serverless·tdsql·腾讯云数据库
代码雕刻家11 小时前
数据结构-3.9.栈在递归中的应用
c语言·数据结构·算法
Kalika0-013 小时前
猴子吃桃-C语言
c语言·开发语言·数据结构·算法