逆置单链表可能是一个非常非常常见的数据结构的题目了
蛮经典的
在这里再写一次。
其实我还是写了蛮久的,汗一个我的编程能力~
只放了main方法 不过够了
蛮经典的
在这里再写一次。
其实我还是写了蛮久的,汗一个我的编程能力~
只放了main方法 不过够了
public static void main(String[] args) {
Node a1 = new Node("a",null);
Node a2 = new Node("b",null);
Node a3 = new Node("c",null);
Node a4 = new Node("d",null);
a1.next = a2;
a2.next = a3;
a3.next = a4;
Node head = a1;
Node pre = null;
Node next = head.next;
while(next != null) {
head.next = pre;
pre = head;
head = next;
next = next.next;
}
head.next = pre;
//print all
Node p;
p = head;
for(;p != null;p = p.next) {
System.out.print(p.value + " ");
}
}