当前位置:网站首页>双链表的创建
双链表的创建
2022-07-31 10:08:00 【柯基@】
- 尾插法
void createDlistR(DLNode *&L,int a[],int n){
DLNode *s,*r;
int i;
L=(DLNode*)malloc(sizeof(DLNode));
L->prior=NULL;
L->next=NULL;
r=L;
for(i=0;i<n;i++){
s=(DLNode*)malloc(sizeof(DLNode));
s->data=a[i];
r->next=s;
s->prior=r;
r=s;
}
r->next=NULL;
}
- 头插法
void createDlistR(DLNode *&L,int a[],int n){
DLNode *s;
int i;
L=(DLNode*)malloc(sizeof(DLNode));
L->prior=NULL;
L->next=NULL;
for(i=0;i<n;i++){
s=(DLNode*)malloc(sizeof(DLNode));
s->data=a[i];
s->next=L->next;
if(L->next!=NULL)
L->next->prior=s;
L->next=s;
s->prior=L;
}
}
边栏推荐
猜你喜欢
随机推荐
The fifth chapter
Data Middle Office Construction (6): Data System Construction
Mybaits 常用问题详解
Gradle系列——Groovy概述,基础使用(基于Groovy文档4.0.4)day2-1
nodeJs--url模块
Come n times - 09. Implement queues with two stacks
前序、后序及层次遍历实现二叉树的序列化与反序列化
恋爱期间的赠与能否撤销
DC-7-vulnhub
踩水坑2 数据超出long long
The big-eyed Google Chrome has also betrayed, teach you a trick to quickly clear its own ads
Are postgresql range queries faster than index queries?
Centos7 install mysql5.7
VMware下安装win10
Kotlin—基本语法(一)
NowCoderTOP28-34 binary tree - continuous update ing
GVINS论文阅读笔记
csdn文件导出为pdf
感情危机,朋友的网恋女友要和他闹分手,问我怎么办
js right dot single page scrolling introduction page









