All pastes #352183 Raw Edit

Trie

public c v1 · immutable
·published 2007-02-12 17:15 UTC
rendered paste body
#include<stdio.h>typedef struct Trie{        struct Trie *children[26];        bool is_end_of_word;}Trie;Trie *insert(Trie * node, char **words, int n, int start, int end, int char_pos){     int start_pos = start;     int end_pos = end;          int count = start_pos;     char ch;          node = (Trie *)malloc(sizeof(Trie));     node->is_end_of_word = false;          if(start == end)              if(words[start][char_pos] == '\0')              {                   node->is_end_of_word = false;                                 return node;              }          while(count <= end)     {                 ch = words[start_pos][char_pos];                 while(count < end){                             if(words[count++][char_pos] == ch)                                  continue;                             else                                  break;                 }                 insert(node->children[ch-'a'], words, start_pos,count-1, char_pos+1);                 end_pos = start_pos = count;                 count -= 1;     }     return node;}