(转)print算法实现链表的遍历.
reverse 算法实现链表的倒置,并让链表的头指针L指向新表的表头。
Source code:
#include "linklist.h"
link l;
void Print(link l)
{
link p;
p=l;
while (P!=NULL)
{
visite_snode(P,1);
p=p->next;
}
}
void Reverse(link &L)
{
link h,u;
h=NULL;
while(l!=NULL)
{
u=L;
L=L->next;
u->next=h;
h=u;
}
l=u;
}
void main()
{
load_hsllist(l);
comput_sllist_card(l,50,100);
disp_hsllist("Sllist",l);
Print(l);
Reverse(l->next);
comput_sllist_card(l,50,250);
disp_hsllist("Reversed",l);
}
评论