代码集-字典树

//字典树
public class DirectoryTree {
	//根结点
	private DirTreeNode root=new DirTreeNode();
	public static void main(String[] args) {
		DirectoryTree tree=new DirectoryTree();
		tree.insert("Hello");
		tree.insert("KeepThinking");
		tree.insert("Hi");
		System.out.println(tree.search("Keep"));
		tree.insert("Keep");
		tree.insert("Keep");
		tree.insert("Keep");
		System.out.println(tree.search("Keep"));
		System.out.println(tree.search("keepThinking"));
	}
	//插入
	public  void insert(String word){
		word=word.toLowerCase();
		//父结点
		DirTreeNode preNode=root;
		//下一个结点
		DirTreeNode nextNode=null;
		char[] words=word.toCharArray();
		int length=words.length;
		for(int i=0;i


你可能感兴趣的:(java)