双向链表代码.doc

上传人:cl****1 文档编号:543500481 上传时间:2023-02-19 格式:DOC 页数:3 大小:38.01KB
返回 下载 相关 举报
双向链表代码.doc_第1页
第1页 / 共3页
双向链表代码.doc_第2页
第2页 / 共3页
双向链表代码.doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《双向链表代码.doc》由会员分享,可在线阅读,更多相关《双向链表代码.doc(3页珍藏版)》请在金锄头文库上搜索。

1、双向循环链表 创建,插入,删除,输出#include#includeint n=0;typedef struct nodeint num;struct node *left;struct node *right; node; node *head; void create()/建立双向链表 node *p1,*p2; head=NULL;head-left=head;head-right=head; p1=p2=(node *)malloc(sizeof(node); printf(please input numn); scanf(%d,&p1-num);while(p1-num!=0) n

2、+; if(n=1) head=p1; p1-left=p1; p1-right=p1; Else p2-right=p1; p1-left=p2; p2=p1; p1=(node *)malloc(sizeof(node); printf(please input numn); scanf(%d,&p1-num); p2-right=head; head-left=p2;void list()/打印双向链表 node *p; p=head; if(p) while(p-right!=head) printf(%d ,p-num); p=p-right; printf(%d ,p-num);

3、printf(n);void del()/删除某个节点 node *p1,*p2,*p3;int num; p3=p1=head; printf(please input del numn); scanf(%d,&num); if(p1=NULL) printf(emptyn); else while(p1-num!=num&p1-right!=head) p2=p1; p1=p1-right; while(p3-right!=head) p3=p3-right; if(p1-num=num) if(p1=head) head=p1-right; head-left=p3; p3-right=

4、p3; Else p2-right=p1-right; else printf(not foundn); void insert1()/* 后插法*/ node *p0,*p1,*p2; p1=p2=head; p0=(node *)malloc(sizeof(node); printf(please input numn); scanf(%d,&p0-num); if(!p1) head=p0; p0-left=p0; p0-right=p0; Else while(p2-right!=head) p2=p2-right; p2-right=p0; p0-left=p2; p0-right=

5、head; head-left=p0; void insert()/* 前插法*/ node *p,*p1,*p2; p=head;p2=head-left; p1=(node *)malloc(sizeof(node); printf(please input numn); scanf(%d,&p1-num); if(!p) head=p1; p1-left=NULL; p1-right=NULL; Else head=p1; p1-right=p; p-left=p1; head-left=p2; p2-right=head; void main() create(); list(); insert(); list(); del(); list();

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 社会民生

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号