坚持到底就是胜利

用心去做好这件事情

统计

留言簿(1)

阅读排行榜

评论排行榜

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;
  
}

posted on 2006-11-20 22:11 ailab 阅读(169) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理