链表反转

/*节点的类定义*/
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;
    }
}

posted @ 2012-09-04 17:33  杨柳岸边  阅读(107)  评论(0)    收藏  举报