当前位置:网站首页>双链表有关操作
双链表有关操作
2022-07-01 12:05:00 【Between the steps】
双链表有关操作
双链表有关操作
双链表的初始化
#include<stdio.h>
typedef struct DNode{
int data;
struct DNode *prior,*next;
}DNode,*DLinklist;
//初始化双链表
bool InitDLinkList(DLinklist &L){
L=(DNode*)malloc(sizeof(DNode)); //分配一个头结点
if(L==NULL){
return false;
}
L->prior=NULL; //头结点的prior永远为NULL
L->next=NULL;
return true;
}
//链表判空
bool Empty(DLinklist L){
if(L->next==NULL)
return true;
else
return false;
}
void main(){
DLinklist L;
InitDLinkList(L);
}
双链表的插入
bool InsertNextDNode(DNode *p,DNode *s){
if(p==NULL||s==NULL){
return false;
}
s->next=p->next; //将结点*s插入到结点*p之后
if(p->next!=NULL)
p->next->prior=s;
s->prior=p;
p->next=s;
return true;
}


双链表结点的删除
//删除p结点的后继结点
bool InsertNextDNode(DNode *p){
if(p==NULL){
return false;
}
DNode *q=p->next; //找到p的后继结点
if(q==NULL){
return false; //p没有后继结点
}
p->next=q->next;
if(q->next!=NULL) //q结点不是最后一个结点
q->next->prior=p
free(q); //释放结点空间
return true;
}


销毁一个双链表
双链表的遍历
边栏推荐
- About keil compiler, "file has been changed outside the editor, reload?" Solutions for
- Talk about the pessimistic strategy that triggers full GC?
- GID: open vision proposes a comprehensive detection model knowledge distillation | CVPR 2021
- The Missing Semester
- Impressive bug summary (continuously updated)
- 博途V15添加GSD文件
- 邻接矩阵无向图(一) - 基本概念与C语言
- Botu V15 add GSD file
- 我在中山,到哪里开户比较好?实际上网上开户安全么?
- 强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐
猜你喜欢

LeetCode力扣(剑指offer 31-35)31. 栈的压入弹出序列32I.II.III.从上到下打印二叉树33. 二叉搜索树的后序遍历序列34. 二叉树中和为某一值的路径35. 复杂链表的复制

Onenet Internet of things platform - mqtt product devices send messages to message queues MQ

自组织是管理者和成员的双向奔赴

Learning summary on June 28, 2022

Typora adds watermarks to automatically uploaded pictures

Istio、eBPF 和 RSocket Broker:深入研究服务网格

Neo4j Chinese developer monthly - issue 202206

Indefinite integral

CPI tutorial - asynchronous interface creation and use

Technology sharing | MySQL: how about copying half a transaction from the database?
随机推荐
How does Nike dominate the list all the year round? Here comes the answer to the latest financial report
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 3
Self organization is the two-way rush of managers and members
指定的服务已标记为删除
Leetcode (Sword finger offer) - 58 - ii Rotate string left
Neo4j Chinese developer monthly - issue 202206
耐克如何常年霸榜第一名?最新財報答案來了
用于分类任务的数据集划分脚本
Learning summary on June 30, 2022
想问问,证券开户有优惠吗手机开户是安全么?
Consolidate -c operator
巩固-C#运算符
Redis configuration environment variables
Custom grpc plug-in
C#依赖注入(直白明了)讲解 一看就会系列
Redis' attack tactics
Impressive bug summary (continuously updated)
LeetCode 454. 四数相加 II
Build yocto system offline for i.mx8mmini development board
Use set_ Handler filters out specific SystemC wrapping & error messages

