C++练习 | 不使用头插法逆转单链表

void D(PBook pHead)
{
    PBook p,q,s;
    p=pHead->next->next;
    q=p->next;
    s=q->next;
    
    pHead->next->next=NULL;
    p->next=pHead->next;
    
    q->next=p;
    p=q;
    q=s;
    
    while(q->next!=NULL)
    {
        s=q->next;
        q->next=p;
        p=q;
        q=s;
    }
    q->next=p;
    pHead->next=q;
}

 

posted @ 2019-10-07 17:05  洛枫大人  阅读(123)  评论(0编辑  收藏  举报