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;

}

相关推荐
一叶落4384 分钟前
【LeetCode 289】生命游戏(C语言)|原地算法 + 状态标记法
c语言·数据结构·算法·leetcode·游戏
程序猿编码19 分钟前
轻量又灵活:一款伪造TCP数据包的iptables扩展实现解析(C/C++代码实现)
linux·c语言·网络·c++·tcp/ip·内核·内核模块
AI科技星1 小时前
从v=c螺旋时空公理出发的引力与电磁常数大统一
c语言·开发语言·人工智能·线性代数·算法·矩阵·数据挖掘
J987T1 小时前
C语言、微机原理等
c语言·开发语言
努力中的编程者10 小时前
栈和队列(C语言底层实现环形队列)
c语言·开发语言
一叶落43810 小时前
题目:15. 三数之和
c语言·数据结构·算法·leetcode
码不停蹄Zzz11 小时前
C语言——神奇的static
java·c语言·开发语言
会编程的李较瘦14 小时前
【C语言程序设计学习】一、C语法基础
c语言·开发语言·学习
困死,根本不会14 小时前
【C 语言】指针学习笔记:从底层原理到实战应用
c语言·开发语言·笔记·学习·算法
自动化和Linux14 小时前
C语言_scanf(),strlen(),size()的特性和各自的区别
c语言·开发语言