从头到尾打印链表

(递归实现)

package pers.chao.niuke.ch1.p1._8从尾到头打印链表;

public class Main {

    Node head;
    public static void print(Node head){
        if(head==null){
            return ;
        }else{
            if(head.next!=null){
                print(head.next);
            }
            System.out.print(head.data+"\t");
        }
    }
}
class Node{
    Node next;
    int data;

    public Node(int data) {
        this.data=data;
        this.next=null;
    }
}

 

你可能感兴趣的:(算法与数据结构)