chichidails
New Member
I have a text file which contains one line "website which allows me to do various". I want to build a tree from it such that:[*]Take the first character of each word in the file, check if that character already exists in the tree, if not, add it (as the first level of the tree)[*]Take the second character of the word and add it to the second level of the tree (if it doesn't already exist there). 3.Finally add the whole word. maybe the picture will help.\[code\] Root---w | | | -- e --- website (word from the file) | -- h --- which (word from the file) | |-- a | | | -- l --- allows (word from the file) |-- m | -- e -- me (word from the file)\[/code\]etcHow do I do that ? I know how to parse the text file. This is my code:\[code\] public void parse(File f) throws Exception { Node root = new Node('+'); //create a root node BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(f))); String line; //for checking english characters Pattern nonEng = Pattern.compile("[^a-z]"); while((line = br.readLine())!=null){ String[] words = line.toLowerCase().split(" "); for(int i = 0; i < words.length; i++){ //for checking english characters if (!nonEng.matcher(words).find()){ // add words here ?? addToTree(words, root); } } }//end of while}\[/code\]