#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;} 不写不知道,原来这么简单。造成卡壳的地方是头指针的理解出现偏差。

评论