src/spelling/AutoCompleteDictionaryTrie.java
/** Insert a word into the trie.
	 * For the basic part of the assignment (part 2), you should ignore the word's case.
	 * That is, you should convert the string to all lower case as you insert it. */
Insert a word into the trie.
For the basic part of the assignment (part 2), you should ignore the word's case.
That is, you should convert the string to all lower case as you insert it.
Insert a word into the trie . For the basic part of the assignment ( part 2 ) you should ignore the word ' s case . That is you should convert the string to all lower case as you insert it .
public boolean addWord(String word)
	{
		boolean addWordStatus=false;
		word = word.toLowerCase();
		if (!word.isEmpty()) {
			TrieNode next = null;
			TrieNode currentNode = null;
			currentNode = root;
			char [] wordChar =word.toCharArray();
			char ch;
			for (int i=0; i< word.length(); i++) {
				ch=wordChar[i];
				next = currentNode.insert(ch);
				if (null != next) {
					currentNode = next;
					if(i==wordChar.length-1){
						currentNode.setEndsWord(true);
						size++;
						addWordStatus=true;
					}
				} else { 
					if(i==wordChar.length-1 && !currentNode.getChild(ch).endsWord()){
						currentNode.getChild(ch).setEndsWord(true);
						size++;
						addWordStatus=true;
					}
					currentNode = currentNode.getChild(ch);
				}
			}
			return addWordStatus;
		} else {
			return addWordStatus;
		}
	}
public boolean addWord ( String word ) { boolean addWordStatus = false ; word = word . toLowerCase ( ) ; if ( ! word . isEmpty ( ) ) { TrieNode next = null ; TrieNode currentNode = null ; currentNode = root ; char [ ] wordChar = word . toCharArray ( ) ; char ch ; for ( int i = 0 ; i < word . length ( ) ; i ++ ) { ch = wordChar [ i ] ; next = currentNode . insert ( ch ) ; if ( null != next ) { currentNode = next ; if ( i == wordChar . length - 1 ) { currentNode . setEndsWord ( true ) ; size ++ ; addWordStatus = true ; } } else { if ( i == wordChar . length - 1 && ! currentNode . getChild ( ch ) . endsWord ( ) ) { currentNode . getChild ( ch ) . setEndsWord ( true ) ; size ++ ; addWordStatus = true ; } currentNode = currentNode . getChild ( ch ) ; } } return addWordStatus ; } else { return addWordStatus ; } }
Insert a word into the trie.
Insert a word into the trie .
// ch node does not exist: a new node with ch has been created and returned:move currNode to this and check for next char //counter++; // node ch exists as a child of the currentNode: move currentNode to the child of currentNode //System.out.println( " currentNode ="+currentNode.getText() + " #$#$ " +currentNode.getValidNextCharacters().toString());