高手看看我的C语言代码单链表实现就地逆置
单链表实现就地逆置#include #include struct type{ int date; struct type * next;}first;int main(){ struct type * opp(struct type * head);//定义算法 struct type * head=&first; struct type * p1=head; struct type * p2=NULL; first.date=0; for(int i=1; i<13; i++) { p2=(struct type *)malloc(sizeof(struct type)); p2->date=i*2+1; p1->next=p2; p1=p1->next; } p2->next=NULL; p1=NULL;//构造一个递增的单链表做实验 printf("单链表为\n"); p2=head; for(; p2->next!=NULL; p2=p2->next) { printf("%d ",p2->date); } printf("\n"); head=opp(head); p2=head; for(; p2->next!=NULL; p2=p2->next) { printf("%d ",p2->date); } printf("\n"); return 0;} struct type * opp(struct type * head){ struct type * pro=head; struct type * flag=head->next; struct type * next=flag->next; pro->next=NULL; for(; next->next!=NULL;) { flag->next=pro; pro=flag; flag=next; next=next->next; } next->next=flag; return next;}