public class Node { private int data; private Node next; public int getData() { return data; } public void setData(int data) { this.data = data; } public Node getNext() { return next; } public void setNext(Node next) { this.next = next; } public Node() { } public Node(int data) { this.data = data; } public Node(int data, Node next) { this.data = data; this.next = next; } /*递归遍历*/ public static void getData(Node node){ //递归出口 if(node == null){ return; } System.out.println(node.getData());//递归的功能 getData(node.getNext()); } public static void main(String[] args){ Node root = new Node(0); Node node01 = new Node(1); Node node02 = new Node(2); root.setNext(node01); node01.setNext(node02); getData(root); } }
单链表的遍历
最新推荐文章于 2024-01-27 17:21:37 发布