#include <stdio.h> #include <stdlib.h> typedef struct node {int x; struct node *next; }NODE; NODE *padd(NODE *pa) { NODE *p1,*p2,*p; p1=p2=pa; while(p1) { if(p1->x%2==0 && p1!=pa) { p=p1;p1=p1->next; p2->next=p1; p->next=pa;pa=p; } else {p2=p1;p1=p1->next; } } return pa; } int main(int argc, char *argv[]) { NODE a[10]={{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}},*ha=a,*p; int i; for(i=0;i<9;i++) a[i].next=&a[i+1]; a[9].next=NULL; ha=padd(ha); p=ha; while(p) printf("%d ",p->x);p=p->next; putchar(' '); return 0; }
运行结果: