package swordOffre.gaopengyu; class LinkedListNode { int val; LinkedListNode next; public LinkedListNode(int val, LinkedListNode next) { this.val = val; this.next = next; } } public class ReversePrintLinkedlist6 { public static void main(String[] args) { LinkedListNode node5 = new LinkedListNode(5, null); LinkedListNode node4 = new LinkedListNode(4, node5); LinkedListNode node3 = new LinkedListNode(3, node4); LinkedListNode node2 = new LinkedListNode(2, node3); LinkedListNode node1 = new LinkedListNode(1, node2); LinkedListNode root = new LinkedListNode(0, node1); reversePrintLinkedlist(root); } public static void reversePrintLinkedlist(LinkedListNode node) { if (node != null) { reversePrintLinkedlist(node.next); System.out.print(node.val + "->"); } } }
从尾到头打印链表6
最新推荐文章于 2022-11-01 14:28:57 发布