检查了半天 想不出
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"));
}
}