标题:检查了半天 想不出
取消只看楼主
X15810803158
Rank: 2
等 级:论坛游民
帖 子:49
专家分:36
注 册:2015-2-24
结帖率:91.67%
 问题点数:0 回复次数:0 
检查了半天 想不出


class Link{
    private class Node{
        private String date;//数据
        private Node next;//下一个节点
        public Node(String date){
            this.date = date;
        }
        public void addNode(Node newNode){
            if(this.next == null){
                this.next = newNode;
            }else{
                this.next.addNode(newNode);
               
            }
            
        }
        public boolean containsNode(String date){//查询
            if(date.equals(this.date)){
                return true;
            }else{
                if(this.next != null){
                    return this.next.containsNode(date);
                }else{
                    return false;
                }
            }
        }
    }
    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 boolean contains(String date){
            if(date == null ){
                return false;
            }
                return this.root.containsNode(date);
            
        }
        
    }
   
}

public class LinkDemo{
   
    public static void main(String[] args){
        Link all = new Link();
        all.add("h");
        all.add("e");

        System.out.println(all.contains("h"));
    }
}
搜索更多相关主题的帖子: private public null 
2016-12-06 13:54



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-472038-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.416910 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved