可以翻转链表之后 遍历打印 但是破坏了链表原有的结构,不推荐。

使用栈 先进后出 将节点遍历压入栈中,出栈打印

    public static void reversePrint(Node head){
        if (head.next == null){
            return;//空链表,不能打印
        }
        Stack<Node> stack = new Stack();
        Node cur = head.next;
        while (cur != null){
            //入栈
            stack.push(cur);
            cur = cur.next;
        }
        while (stack.size()>0){
            //出栈
            Node pop = stack.pop();
            System.out.println(pop);
        }
    }

 

posted on 2020-08-17 17:55  audience7510  阅读(126)  评论(0)    收藏  举报