MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / insertTrie

Function insertTrie

CPP/Tries/autoComplete.cpp:35–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33};
34
35void insertTrie(TrieNode *root, string &s, int index){
36 for (int i=0; i<s.size(); i++){
37 if (root->alphabets[s[i]-'a']==NULL){
38 root->alphabets[s[i]-'a']=new TrieNode();
39 }
40 if (root->indexes.size()<5) root->indexes.push_back(index);
41 root=root->alphabets[s[i]-'a'];
42 }
43 if (root->indexes.size()<5) root->indexes.push_back(index);
44 root->endOfword=true;
45}
46
47bool comp(pair <string,int> p1, pair <string,int>p2){
48 if (p1.second>=p2.second) return true;

Callers 1

solveFunction · 0.85

Calls 2

push_backMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected