当前位置:网站首页>双链表的创建
双链表的创建
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;
}
}
边栏推荐
猜你喜欢
随机推荐
怎样使用浏览器静默打印网页
loadrunner脚本--添加事务
Simple understanding of GCD
SQLite3交叉编译
第二十二课,实例化(instancing)
js部门预算和支出雷达图
Chapter VII
Build finished with errors/Executable Not Found
Day113. Shangyitong: user authentication, Alibaba Cloud OSS, patient management
js滚动条滚动到指定元素
js department budget and expenditure radar chart
如何将亚马逊广告添加到您的 WordPress 网站(3 种方法)
Are postgresql range queries faster than index queries?
Kotlin—基本语法(二)
djangoWeb应用框架+MySQL数据4
PyQt5快速开发与实战 9.4 Matplotlib在PyQt中的应用
Kotlin—基本语法 (五)
一些计时软件,生产力工具
qt pass custom structure parameters in different threads
js implements the 2020 New Year's Day countdown bulletin board