数据结构 - java翻转链表是如何实现的?
本文介绍了数据结构 - java翻转链表是如何实现的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
public class Node {
public int value;
public Node next;
public Node(int data) {
this.value = data;
}
public Node reverse(Node head) {
Node pre = null;
Node next = null;
while (head != null) {
next = head.next;
head.next = pre;
pre = head;
head = next;
}
return pre;
}
这段代码while循环中他是如何翻转的?想要详细一点的,debug了几次还是没弄懂具体是怎么回事
解决方案
Ps:建议先多了解一下链表
这篇关于数据结构 - java翻转链表是如何实现的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文