#include#include #define ElemType inttypedef struct node{ ElemType data; struct node *next;}node,*link;void display(link list);//使用头插法link createH(link l){ ElemType i; l->next=NULL; link p=NULL; while(1){ /*p=(link)malloc(sizeof(node)); if (NULL == p) { printf("memory out of use/n"); return l; } */ for(i=1;i<10;i++){ p=(link)malloc(sizeof(node)); p->data=i; p->next=l->next; l->next=p; } break; /* if(scanf("%d",&p->data)!=EOF){ p->next=l->next; l->next=p; }else{ break; }*/ } return l; }link createF(link list){ link p,k; list->next=NULL; int i; for(i=1;i<10;i++){ k=list; p=(link)malloc(sizeof(node)); p->data=i; while(k->next!=NULL){ k=k->next; } p->next=NULL; k->next=p; } return list;}//方法一link reverseA(link prev,link cur){ link list=NULL; if(cur==NULL){ return prev; } list=reverseA(cur,cur->next); cur->next=prev; return list;}//方法二link reverseB(link p){ if( p->next==NULL){ return p; } link ph=reverseB(p->next); p->next->next=p; p->next=NULL; return ph;}//方法三link reverseC(link l){ link p=NULL,q=NULL; p=l->next; l->next=NULL;//头结点分离 while(p!=NULL){ q=p; p=p->next; q->next=l->next; l->next=q; } return l;}//方法四link reverseD(link l){ link p=NULL,q=NULL; if(l==NULL){ return l; } p=l; q=p->next; if(q==NULL){ return p; }else{ l=reverseR(q); } q->next=p; p->next=NULL; return l;}//方法五link reverseE(link p){ link pre=NULL,pnext=NULL,cur=p; while(cur!=NULL){ pnext=cur->next; cur->next=pre; pre=cur; cur=pnext; } return pre;}//按照位置删除节点link delete(link list,int i){ link p=list,k=NULL; if(i==1){ return list=list->next; } int j=2; while(p!=NULL){ if(i==j){ p->next=p->next->next; break; } p=p->next; j++; } free(p); return list;}void display(link list){ link p=list; while(p!=NULL){ printf("%4d",p->data); p=p->next; } printf("\n");}void main(){ link list,p,r; list=(link)malloc(sizeof(node)); p=(link)malloc(sizeof(node)); r=(link)malloc(sizeof(node)); p=createF(list); display(p); r=reverseA(NULL,p); display(r); r=reverseB(p); display(r);}