链表的逆序

NODE* reverse_link(NODE *head)        //链表的逆序 
{

    //利用一个辅助指针来 将原来的顺序继续下去,然后用另一个指针来保持新的顺序
    int a1;
    NODE* before_circle = head->next;    //指向第一个
    NODE* new_circle = before_circle->next;    //指向第二个
    NODE* temp;
    while(temp !=NULL)
    {
        temp = new_circle->next;
        new_circle->next = before_circle;
        before_circle = new_circle;
        new_circle = temp;
    }
    head->next->next = NULL;
    head->next = new_circle;//头指针指向原来的末节点
    return head;
}

 

上一篇:每日日报


下一篇:c++之this指针探究