【链表】逆序打印链表
1 public class Main { 2 3 // 逆序打印链表 4 public void reversePrint(Node node) { 5 if (node == null){ 6 return; 7 } 8 reversePrint(node.next); 9 System.out.println(node.data); 10 } 11 12 public Node createListNodes() { 13 Node node7 = new Node(7, null); 14 Node node6 = new Node(6, node7); 15 Node node5 = new Node(5, node6); 16 Node node4 = new Node(4, node5); 17 Node node3 = new Node(3, node4); 18 Node node2 = new Node(2, node3); 19 Node node1 = new Node(1, node2); 20 Node head = new Node(0, node1); // head pointer 21 22 return head; 23 } 24 25 public static void main(String[] args) { 26 Main main = new Main(); 27 main.reversePrint(main.createListNodes().next); 28 29 } 30 31 }