codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
struct trie { struct trie *child[26]; int count; char letter; }; struct trie* newtrie(char newchar) { struct trie* r = malloc(sizeof(struct trie)); memset(r, 0, sizeof(struct trie)); r->letter = newchar; return r; } int addWordOccurrence(const char* word) { struct trie *root = newtrie(0); struct trie *initRoot=root; int count; int x=strlen(word); printf("%d",x); int i; for(i=0; i<x; i++) { int z=word[i]-97; if(word[i]=='\n') { z=word[i-1]-97; root->child[z]->count++; root=initRoot; } if (root->child[z] == NULL) root->child[z] = newtrie(word[i]); root->child[z]=root; } return 0; } int main() { addWordOccurrence("cat\ndog\napple\n"); addWordOccurrence("cat\ndog\napple\n"); addWordOccurrence("cat\ndog\napple\n"); addWordOccurrence("cat\ndog\napple\n"); addWordOccurrence("cat\ndog\napple\n"); addWordOccurrence("cat\ndog\napple\n"); return 0; }
Private
[
?
]
Run code
Submit