返回带头结点的单链表L的逆转链表。

返回带头结点的单链表L的逆转链表。

List Reverse( List L )
{
    
    
    Position Old_head, New_head, Temp;
    New_head = NULL;
    Old_head = L->Next;

    while ( Old_head )  {
    
    
        Temp = Old_head->Next;
        
 Old_head->Next=New_head
;  
        New_head = Old_head;  
        Old_head = Temp; 
    }
    
L->Next=New_head
;
    return L;
}

猜你喜欢

转载自blog.csdn.net/weixin_41438423/article/details/125413265