数据结构练习(17)反转链表
http://zhedahht.blog.163.com/blog/static/2541117420073471124487/
链表操作的经典,简短的代码写出健壮的程序,这才是编程之美啊
struct ListNode { int value; ListNode *next; }; ListNode * reverse_list(ListNode *head) { ListNode *rvs = NULL; ListNode *pre = NULL; ListNode *node = head; while (node != NULL) { ListNode *next = node->next; if (next != NULL) rvs = node; node->next = pre; pre = node; node = next; } return rvs; }
-------------------------------------------------------
kedebug
Department of Computer Science and Engineering,
Shanghai Jiao Tong University
E-mail: kedebug0@gmail.com
GitHub: http://github.com/kedebug
-------------------------------------------------------