Skip to content

Latest commit

 

History

History
17 lines (13 loc) · 459 Bytes

从头到尾打印链表.md

File metadata and controls

17 lines (13 loc) · 459 Bytes

####从头到尾打印链表

输入一个链表的头结点,逆序打印每个节点的值。

public void travelList(Node head){
    Stack<T> stack = new Stack<>();
    
    Node current = head;
    
    while (current != null){
          stack.push(current.value);
          current = current.next;
    }
    
    for (int i = 0; i < stack.size(); i++){
        System.out.println(stack.pop());
    }
} }