1 #include<stdio.h> 2 #include<stdlib.h> 3 typedef struct Node{ 4 int data; 5 Node*pre,*next; 6 }Node,*LinkList; 7 CreateLinkList(LinkList*L) 8 { 9 *L=(LinkList)malloc(sizeof(Node)); 10 Node*t,*r; 11 int length,e; 12 scanf("%d",&length); 13 r=*L; 14 for(int i=1;i<=length;i++) 15 { 16 scanf("%d",&e); 17 t=(LinkList)malloc(sizeof(Node)); 18 t->data=e; 19 r->next=t; 20 t->pre=r; 21 r=t; 22 } 23 r->next=*L; 24 (*L)->pre=r; 25 } 26 ReSet(LinkList L) 27 { 28 Node*t,*tnext;//遍历原表L 29 Node*left,*right;//分别从头部与尾部插入奇、偶结点 30 int i=1; 31 left=L,right=L; 32 t=L->next; 33 while(t!=L) 34 { 35 tnext=t->next; 36 if(i%2==0) 37 { 38 right->pre=t; 39 t->next=right; 40 right=t; 41 } 42 else 43 { 44 left->next=t; 45 t->pre=left; 46 left=t; 47 } 48 i++; 49 t=tnext; 50 } 51 left->next=right; 52 right->pre=left; 53 } 54 Order(LinkList L) 55 { 56 Node*t=L->next; 57 while(t!=L) 58 { 59 printf("%d ",t->data); 60 t=t->next; 61 } 62 } 63 int main() 64 { 65 LinkList L; 66 CreateLinkList(&L); 67 ReSet(L); 68 Order(L); 69 return 0; 70 }