与上题不同的是,不要反转链表,只做输出即可
解法:循环入栈,循环出栈,over~
//逆序打印链表
public static void reversePrint(heroNode head){
if (head.next == null){
return;
}
Stack<heroNode> stack = new Stack<>();
heroNode cur = head.next;
while (cur != null){
stack.push(cur);
cur = cur.next;
}
while (stack.size() > 0){
System.out.println(stack.pop());
}
}