dream come true 5!

dream come true 5!

reverse list
recursion and none-recursion

node  * reverse_list(node  * head)
{
  
if(head == null || head->next == null)
      
return head;
  node 
*cur = head->next;
  node 
*pre = head;
  node 
*next = null;
  
while(cur != null)
  
{
     next 
= cur->next;
     cur
->next = pre;
     pre 
= cur;  
     cur 
= next;
  }

  head
->next = null;
  head 
= pre;
  reurn head;
}


node  * reverse_list(node  * head)
{
  
if(head == null || head->next == null)
    
return head;
  node 
*cur = head->next;
  node 
*next = null;
  head
->next = null;
  
while(cur != null)
 
{
    next 
= cur->next;
    cur
->next = head;
    head 
= cur;
    cur 
= next;
 }

  
return head;
  
}

你可能感兴趣的:(dream come true 5!)