注册 登录
编程论坛 JAVA论坛

大家帮忙看看 ,到底哪错了,谢谢

X15810803158 发布于 2016-12-05 11:34, 1854 次点击
package mypro01;

class Node {//只是作为一个数据的载体
    private String date;
    private Node next;//下一个载体
    public Node(String date){
        this.date = date;
    }
    public String getDate(){
        return this.date;
    }
    public void setNext(Node next){
        this.next = next;
    }
    public Node getNext(){
        return this.next;
    }
    public void addNode(Node newNode){
        if(this.next == null){//当前的下一个节点空位
            this.next = newNode;//保存新节点
        }else{
            this.next.addNode(newNode);
        }
        
    }
    public void printNode(){
        System.out.println(date);
        if(this.next != null){
            this.next.printNode();
        }
    }
}

class Link{//此类专门操作节点
    private Node root;//根节点
    public void add(String date){//保存数据
        Node newNode = new Node(date);//将数据封装在节点之中
        if(this.root == null){//现在没有根节点
            this.root = newNode;//第一个作为根节点
        }else{
            this.root.addNode(newNode);
        }
    }
    public void print(){
        if(this.root!= null){//有数据
            this.root.printNode();//交给根节点
        }
    }
   
}

public class Link2 {
    public static void main(String[] args){
    Link all = new Link();
    all.add("kfsf");
    all.add("dsfdsd");
    all.add("ssdsd");
    all.add("edsds");
    all.print();
    }
}
2 回复
#2
孤独与烈酒2016-12-05 14:05
把你的代码运行了一遍 没有问题
只有本站会员才能查看附件,请 登录
#3
X158108031582016-12-06 13:50
非常感谢,好了,与其它类名重复了。。。。
1