java版 字典树
来源:互联网 发布:淘宝开店加盟靠谱吗 编辑:程序博客网 时间:2024/05/19 20:43
package test;import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.util.LinkedList;import java.util.Scanner;class Trie{public int flag;public char ch;public int leng;public LinkedList<Trie>next;}class save{public Trie root=new Trie();public char[] ss=new char[100];public void BuildTrie(String str){char s[]=new char[100];s=str.toCharArray();int i,j,len=str.length();Trie t=root;for(i=0;i<len;i++){for(j=0;j<t.leng;j++){if(t.next.get(j).ch==s[i])break;}if(j<t.leng) t=t.next.get(j);else{Trie h=new Trie();h.ch=s[i];h.flag=0;if(t.leng==0)t.next=newLinkedList<Trie>();t.next.add(h);t.leng++;t=h;t.leng=0;}}t.flag=1;};public void Show(Trie t,int index){int i;for(i=0;i<t.leng;i++){ss[index]=t.next.get(i).ch;if(t.next.get(i).flag==1){System.out.println(new String(ss,0,index+1));}Show(t.next.get(i),index+1);}}public void set(String name){root.leng=0;try{FileReader one=new FileReader(name);BufferedReader to=new BufferedReader(one);String s=to.readLine();while(s!=null){BuildTrie(s);s=to.readLine();}Show(root,0);}catch(IOException e){};}}public class Main { public static voidmain(String agrs[]){ Scanner in=newScanner(System.in); String name; name=in.next(); save to=newsave(); to.set(name); }}
第一次实现,代码估计有点臭,大牛可以不看……
- java版 字典树
- 字符串 之字典树 算法
- java 版字典树
- java 版字典树
- python 遍历 字典
- 字典树查找字符串(java版)
- ORACLE 数据字典
- Java实现字典树
- 字典树(java)
- 字典树java版本
- 字典树Java模板
- 字典树--java 定义
- java swing 树结构代码
- hdu 2005 第几天? java版
- hdu1113 字典查找 java版
- java字典树 实现统计
- 字典树模板(java)
- Java实现字典树TrieTree
- hdu 1501 Zipper
- 优先队列的使用
- 堆排序的实现(递归)
- hdu 1063 Exponentiation
- 感悟
- java版 字典树
- hdu 1584 蜘蛛牌
- 2012年04月11日的日记
- hdu 1710 Binary Tree Traversals
- Poj 2886 Who Gets the Most Candi…
- 【原创】 线段树学习总结
- hdu 1688 Sightseeing
- 多重背包【优先级队列写法】
- 性能测试的准备