正文

嵌入式实验代码 链表逆置2009-04-07 11:31:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/19880128/42015.html

分享到:

#include <stdio.h>#include <tchar.h>#include <stdlib.h> typedef struct Chain { int a; Chain * Next;}*Head; int _tmain(int argc, _TCHAR* argv[]){ Head p,ReHead; Chain *tmpp,*tmph; Chain *Retmp1,*Retmp2; int a; p=(Head)malloc(sizeof(Chain)); p->Next=NULL; tmph=p; scanf("%d",&a); while(a>0) {  tmpp=(Chain*)malloc(sizeof(Chain));  tmpp->Next=NULL;  tmpp->a=a;  tmph->Next=tmpp;  tmph=tmpp;  scanf("%d",&a); } tmph=p; while(tmph->Next!=NULL) {  tmph=tmph->Next;  printf("%d ",tmph->a); } Retmp1=NULL; Retmp2=p->Next->Next; while(p->Next->Next) {  p->Next->Next=Retmp1;  Retmp1=p->Next;  p->Next=Retmp2;  Retmp2=Retmp2->Next; } p->Next->Next=Retmp1; tmph=p; while(tmph->Next!=NULL) {  tmph=tmph->Next;  printf("%d ",tmph->a); } return 0;} 不写不知道,原来这么简单。造成卡壳的地方是头指针的理解出现偏差。

阅读(1030) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册