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

单链表的倒序:

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语言学习 查看评论
posted on 2010-12-21 19:02  sinbad_li  阅读(339)  评论(0编辑  收藏  举报