链表逆序总结.doc

上传人:大张伟 文档编号:9076425 上传时间:2021-02-01 格式:DOC 页数:4 大小:21KB
返回 下载 相关 举报
链表逆序总结.doc_第1页
第1页 / 共4页
链表逆序总结.doc_第2页
第2页 / 共4页
链表逆序总结.doc_第3页
第3页 / 共4页
链表逆序总结.doc_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《链表逆序总结.doc》由会员分享,可在线阅读,更多相关《链表逆序总结.doc(4页珍藏版)》请在三一文库上搜索。

1、/C+ 逆置单链表的两种方法:循环和递归#includestruct nodeint id;node *next;*head;void add(node *p)node *p1,*p2;p1=head;p2=p1;while(p2)p1=p2;p2=p2-next;p1-next=p;p-next=p2;void show(node *p)while(p)coutidnext;/一种逆置单链表的方法node* rev(node *head) node *prev=NULL,*next=NULL; while(head) next=head-next; head-next=prev; prev=

2、head; head=next; return prev; /另一种逆置单链表的方法/*node * rev(node *head)/递归方式进行链表逆置 if(head=NULL|head-next=NULL) return head; node *tail=rev(head-next); head-next-next=head; head-next=NULL; return tail; */void ()head=new node;head-next=NULL;node *p;p=new node;p-id=7;add(p);p=new node;p-id=8;add(p);p=new node;p-id=9;add(p);cout输出:next);cout逆置后输出:next);

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1