class Node {
Node next = null;//下一个结点
int data;//结点数据
public Node(int data) {
this.data = data;
}
@Override
public String toString() {
return "Node{" +
"data=" + data +
'}';
}
}
/**
* 逆序打印
* @param head
*/
public static void reverseListPrint(Node head){
if (head == null){
return;
}
if (head.next == null){
System.out.println(head.data);
}
Stack stack = new Stack();
Node cur = head;
while(cur != null){
stack.push(cur);
cur = cur.next;
}
while(stack.size() > 0){
System.out.println(stack.pop());
}
}