单链表的倒序

偶尔看到这么个单链表的倒序,觉得写的算法很好(可能我很少去研究算法的原因吧),不画图发现自己还真不知道怎么写的:

单链表的倒序:

struct student *reverse(struct student *head)
{
struct student *p1,*p2,*p3;
p2=head;p3=head->next;
do
{ p1=p2;p2=p3;p3=p2->next;p2->next=p1;
}
while(p3!=NULL);
head->next=NULL;
return(p2);
}

单链表的倒序

 

 

阅读全文
类别:c语言学习 查看评论

转载于:https://www.cnblogs.com/kuwoyidai/archive/2010/12/21/2046250.html