链表倒置
来源:互联网 发布:千千静听软件 编辑:程序博客网 时间:2024/05/01 23:10
#include"iostream"using namespace std; struct node{int data;struct node *next;}; typedef struct node Node; node * reverse( node * head){ node * p,*q;p=head->next;head->next = NULL; while(p!=NULL){ q=p; p=p->next; //修改q会修改p所指的值,所以必须先对p进行保护 q->next = head->next; head->next=q; }return head;} int main(){ node head,*p,*q;int i;head.next=NULL; for(i=0;i<10;i++) {p = new node;p->next=NULL;p->data=i;if(head.next==NULL)head.next=p;elseq->next=p;q=p;} p=head.next;while(p!=NULL){cout<<p->data<<" ";p=p->next;} cout<<endl; p= reverse(&head);p=p->next; while(p!=NULL){cout<<p->data<<" ";p=p->next;} cout<<endl;return 0;}
注意指针在使用前必须初始化
- 链表倒置
- 链表的倒置
- 链表倒置
- 链表倒置
- 链表倒置
- 实现链表倒置
- 链表倒置(逆序)
- 链表的倒置
- [笔试]链表倒置
- 链表的倒置
- 倒置链表
- 链表倒置
- 链表倒置
- 倒置链表
- 链表倒置
- 链表倒置
- 链表的倒置
- 链表的倒置
- 对tableView的学习情况
- USACO_1.3_barn1
- Ubuntu12.04下安装eclipse
- Web前端开发技术
- Ubuntu下配置Intellij的Android开发环境
- 链表倒置
- HDU-1394 Minimum Inversion Number 线段树|树状数组
- cocos2d-x关于home键黑屏和游戏loading界面
- 在VS2010下运行Qt程序
- C++的一些基本问题
- 提高VS2010运行速度的技巧
- 机房收费系统角色分析
- 经典好题!杭电OJ--Ignatius and the Princess I
- Java 之 访问限制:由于对必需的库 C:\Program Files\Java\jre6\lib\ext\j3dutils.jar具有一定限制,因此无法访问类型 Scene