50.单项链表逆置
2015-06-05 10:33
113 查看
#include<stdio.h> #include<stdlib.h> #define N 5 typedef struct node { int date; struct node *next; }NODE; NODE *fun(NODE *h) { NODE *p, *q, *r; p = h; if (p == NULL) return NULL; q = p->next; p->next = NULL; while (q!= NULL) { r = q->next; q->next = p; p = q; q = r; } return p; } NODE *creatlist(int a[]) { NODE *h, *p, *q; int i; for (i = 0;i < N;i++) printf("%d ", a[i]); h =p=q= NULL; for (i = 0;i < N;i++) { q = (NODE*)malloc(sizeof(NODE)); q->date = a[i]; q->next = NULL; if (h == NULL) h = p = q; else { p->next = q; p = q; } } return h; } void outlist(NODE *h) { NODE *p; p = h; if (h = NULL) printf("The list if NULL!\n"); else { printf("\nHead "); do { printf("->%d", p->date); p = p->next; } while (p != NULL); printf("->End\n"); } getchar(); } int main() { NODE *head; int a = { 2,4,6,8,10 }; head = creatlist(a); printf("\nThe original list:\n"); outlist(head); head = fun(head); printf("\n The list after inverting:\n"); outlist(head); return 0; }
相关文章推荐
- wordpress无法安装这个包。: PCLZIP_ERR_MISSING_FILE (-4) : Missing archive file 'C:\WINDOWS\TEMP/wordpress-4.tmp'
- iOS开发 设置状态栏样式
- Tomcat:Custom a common error page valve for all web application in tomcat
- Libertarian
- Android EditText inputType同时设置textPassword和phone
- Linux命令之大文件切分与合并
- poj2155 Matrix
- 如何学习PHP的菊花宝典
- maven入门
- DataTable.AcceptChanges方法有何用处
- 随笔
- PHP 正则表达式
- html小窍门
- JavaScript中constructor()方法的使用简介
- Autolayout uitableviewcell 自适应cell高度
- Volley请求
- Volley请求
- Facebook在settings中不能同步解决方法
- hdu1556 Color the ball
- Unity3d NGUI的drawcall,UISprite与UITexture