ITeye博客

单向链表倒序操作

monkeycn · 2011-05-16 22:27 · 编程语言 · Markdown

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)

  1. #1 楼 · monkeycn · 2011-05-16 23:10

    网龙的面试题目

评论功能维护中,当前仅展示历史评论。