链表逆序
2016-04-09 17:02
267 查看
#include <iostream> #include <stdio.h> #include <stdlib.h> using namespace std; struct node { int date; node *next; }; void shou(node *head) { node *l; l=head->next; while(l!=NULL) { cout<<l->date<<" "; l=l->next; } cout<<endl; } node *ni(node *head) { node *pre,*temp,*l,*now; l=head->next; pre=(node*)malloc(sizeof(node)); pre->next=NULL; int i=0; while(l!=NULL) { now=l->next; temp=l; temp->next=pre; pre=temp; if(i==0) temp->next=NULL; l=now; i++; } head->next=pre; return head; } int main() { int n; node *head,*l,*p; head=(node*)malloc(sizeof(node)); while(~scanf("%d",&n)) { for(int i=0; i<n; i++) { p=(node*)malloc(sizeof(node)); cin>>p->date; p->next=NULL; if(i==0) { head->next=l=p; } else { l->next=p; l=p; } } head=ni(head); shou(head); } return 0; }
相关文章推荐
- android app 图片大小优化办法
- CF 广搜(基础)
- jdk版本间区别
- springAOP配置文件
- 实现进程间通信:匿名管道和命名管道
- 输入输出重定freopen
- 5.5用分水岭算法实现图像分割
- Linux忘记root密码的修改方法
- 结对编程
- HDU-4276 The Ghost Blows Light (树形DP+背包)
- php中合并数组的方法
- 继承
- Qt的常见编译错误
- 动态规划-最长公共子序列(LCS)
- git在国外项目管理平台https://tourscn.codebasehq.com上的使用
- Jmeter接口测试---webservices
- excel 妙用选择性粘贴
- 网络基础
- Python 练习实例10
- php关于盗链问题