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;

}

相关推荐
散峰而望4 小时前
C/C++输入输出初级(一) (算法竞赛)
c语言·开发语言·c++·算法·github
是苏浙7 小时前
零基础入门C语言之C语言实现数据结构之单链表经典算法
c语言·开发语言·数据结构·算法
71-39 小时前
C语言练习题——判断水仙花数(0-100000)
c语言·笔记·学习
jzhwolp10 小时前
从基本链表到侵入式链表,体会内核设计思路
c语言·后端·设计模式
biter down11 小时前
c语言18:结构体位段联合体
c语言·开发语言
程序员buddha12 小时前
C语言操作符详解
java·c语言·算法
云知谷14 小时前
【经典书籍】《代码整洁之道》第六章“对象与数据结构”精华讲解
c语言·开发语言·c++·软件工程·团队开发
树在风中摇曳15 小时前
C语言 | 文件操作详解与实战示例
c语言·开发语言
雨落在了我的手上16 小时前
C语言入门(十六):指针(2)
c语言
say_fall16 小时前
C语言编程实战:每日刷题 - day 1
c语言·开发语言·学习