链表反转
/*节点的类定义*/
class Node
{
Node * next;
};
/*链表的类定义*/
class List
{
Node * head;
};
/*逆转函数——将一个单链表逆转*/
void ReverseList(List & list)
{
Node * pre=NULL;
Node * cur=list.head;
Node * back=cur->next;
while(back!=NULL)
{
cur->next=pre;
pre=cur;
cur=back;
back=cur->next;
}
}
浙公网安备 33010602011771号