c语言描述的双向链表的基本操作
2024-08-24 00:46:36
#include<stdio.h>
#include<stdlib.h>
#define ok 1
#define error 0
typedef int Status;
typedef char ElemType;
typedef struct node{
int data;
struct node *prior;
struct node *next;
}Node;
Node * create(Node *L,int i){
int n;
int j=;
Node *q=L;//保存头结点
while(j<i){
Node *p;
p=(Node *)malloc(sizeof(Node));
printf("请输入结点%d的data:\n",j);
scanf("%d\n",&n);
p->data=n;
p->prior=q;
p->next=NULL;
q->next=p;
q=p;
j++; }
return L; }
Status Insert(Node *L,int i,int m){
int j=;
Node *p=NULL;
while(j<i){
L=L->next;
j++;
}
p=(Node *)malloc(sizeof(Node));
p->data=m;
p->prior=L;
p->next=L->next;
L->next->prior=p;
L->next=p;
return ok; }
void Traverse(Node *L){
L=L->next;
while(L){
printf("%d ",L->data);
L=L->next;
}
}
void main(){
int m=;
Node *p=NULL;
Node *L;
L=(Node *)malloc(sizeof(Node));
L->next=NULL;
L->prior=NULL;
p=create(L,m);
Traverse(L);
Insert(L,,);
Traverse(L);
}
最新文章
- SmartAssembly使用失败记录
- netlink优势
- jQuery的编码标准和最佳实践
- SQL Server 2008 R2——PIVOT 行转列 以及聚合函数的选择
- JQuery.Ajax()的data参数类型
- python处理url中的中文编码,以及其他编码问题
- 【Spring开发】—— Spring Core
- 无法启动ArcSDE服务
- 项目源码--Android即时通讯IM客户端
- sql之表的表达式
- xp主机用VMware9和10安装Ubuntu12.04后无法进入图像界面
- TabControl控件中TabPage的显示和隐藏
- opencv kmeans 图像分割
- 2.Lucene3.6.2包介绍,第一个Lucene案例介绍,查看索引信息的工具lukeall介绍,Luke查看的索引库内容,索引查找过程
- 2019-oo-第二单元总结
- spring-data-redis和jedis版本对应问题
- [20171113]修改表结构删除列相关问题.txt
- 2-MAVEN 基本命令
- memcached 一致性hash原理
- MyBatis拦截器的执行顺序引发的MyBatis源码分析