MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / insert

Method insert

Programs/Trie_Implementation.java:18–31  ·  view source on GitHub ↗
(String word)

Source from the content-addressed store, hash-verified

16
17 //This function insert the given word into our Trie
18 public void insert(String word){
19 TrieNode curr= root;//get the root and create curr node to perform the operation
20
21 for(int i=0; i<word.length(); i++){
22 char ch= word.charAt(i);
23
24 if(curr.children[ch - 'a'] == null){
25 curr.children[ch - 'a']= new TrieNode();//if it is empty put a new Trienode in the curr postion
26 }
27
28 curr= curr.children[ch -'a'];
29 }
30 curr.isEnd= true; //marks the end of the current word in our Trie
31 }
32
33
34//Search function which searches for the word in the Trie. It returns true if the provided word exists in Trie else returns false

Callers 1

mainMethod · 0.95

Calls 1

lengthMethod · 0.80

Tested by

no test coverage detected