天天看点

C语言实现链表逆序

Node* InvertedFromList( Node *pHead )    
 {    
     //A->B->C  
     Node *pPrev = pHead;              //A  
     Node *pNext = pHead->mpNext;      //B  
     Node *pNextNext = nullptr;        //C  
     while( nullptr != pNext )    
     {  
         pNextNext = pNext->mpNext;    //C = B->C  
         pNext->mpNext = pPrev;        //B->A  
   
         pPrev = pNext;                //A = B  
         pNext = pNextNext;            //B = C  
     }  
     pHead->mpNext = nullptr;          //C->B->A->null  
     return pPrev;                     //return C( new head )  
 }    
           

继续阅读