1. 程式人生 > >遞迴實現逆轉連結串列

遞迴實現逆轉連結串列

//遞迴實現逆轉連結串列
ListNode *reverseLink2(ListNode *head)
{
    ListNode *newHead;
    if(head->next==NULL)
        return head;
    newHead=reverseLink2(head->next);
    head->next->next=head;
    head->next=NULL;
    return newHead;
}