首页 > 其他 > 详细

逆转单链表

时间:2018-01-20 11:42:35      阅读:207      评论:0      收藏:0      [点我收藏+]

非递归实现逆转单链表,遍历单链表时,使用三个指针实现逆转:

public static Node reverseNode(Node node) {
if (null == node || null == node.next) {
return node;
}
Node pre = null;
Node cur = node;
Node next = null;
while (null != cur) {
next = cur.next;
cur.next = pre;
pre = cur;
cur = next;
}
return pre;
}

逆转单链表

原文:https://www.cnblogs.com/lizh0209/p/8320065.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!