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;

}

相关推荐
HABuo1 小时前
【linux(四)】套接字编程--socket套接字及其接口认识
linux·运维·服务器·c语言·c++·ubuntu·centos
流年如夢1 小时前
顺序表 -->增、删、查、改等详细操作
c语言·数据结构
我不是懒洋洋1 小时前
手写一个布隆过滤器:从原理到工业级实现
c语言
小年糕是糕手1 小时前
【C/C++刷题集】栈、stack、队列、queue核心精讲
c语言·开发语言·数据结构·数据库·c++·算法·蓝桥杯
Fanfanaas1 小时前
Linux 系统编程 进程篇 (六)
linux·服务器·c语言·开发语言
小年糕是糕手1 小时前
【C/C++刷题集】顺序表、vector、链表、list核心精讲
c语言·开发语言·数据结构·c++·算法·leetcode·蓝桥杯
会编程的土豆1 小时前
从 C/C++ 视角快速上手 Go 语言:核心差异与避坑指南
c语言·开发语言·c++·后端·golang
yuanyuan2o22 小时前
GDB 调试指南
c语言·c++·算法
流年如夢2 小时前
算法效率:复杂度原理解析
c语言·数据结构·算法
上弦月-编程13 小时前
递归实现C语言菱形图案打印
c语言