程序员面试题准备(1)单链表逆置
面试中程序测试,单链表的操作应该是比较容易出现的。单链表的一般操作,比如创建、遍历、插入、删除、清空等常规操作应该是必须掌握的操作,那么程序员面试中可能会出现“非常规”的链表操作,比如链表逆置。
由分析可知,长度为N的链表逆置需循环N次,每次循环将当前结点的Next指针保存,改变当前结点的Next指针指向前一指针(在上一次循环中保存)。
程序参考链接:http://shijuanfeng.blogbus.com/logs/162994602.html
CList* converseList(CList *head) { CList *conHead = head; CList *before = NULL; CList *after = NULL; while (conHead->next != NULL) { after = conHead->next; conHead->next = before; before = conHead; conHead = after; } return *conHead; }
posted on 2012-09-25 23:18 Raphael Lou 阅读(169) 评论(0) 编辑 收藏 举报