`
monkeycn
  • 浏览: 42701 次
  • 性别: Icon_minigender_1
  • 来自: 福州
文章分类
社区版块
存档分类
最新评论

单向链表倒序操作

阅读更多
struct node
{
    int data;
    node* next;
};

// 单向链表头,如何倒序操作
inverse(node* head)
{
node thead;
thead.next = NULL;
for(current = head; current!=null; )
{
     if ( current == head )
     {
node * t = current->next;
         thead.next = current;
current->next = NULL;
         current = t;   
     }
     else
     {
     node * t = current->next;
        node* t2 = thead.next;

        thead.next = current;
        current->next = t2;        

        current = t;    
     }
}

return thead.next;

}
分享到:
评论
1 楼 monkeycn 2011-05-16  
网龙的面试题目

相关推荐

Global site tag (gtag.js) - Google Analytics