#include "treeh.h" //initializers & destroyer tree make_empty_tree(){ return NULL; } node* make_empty_node(){ node*n=malloc(sizeof(node)); n->letter='\0'; n->isEnd=false; for(int i=0;inext[i]=make_empty_tree(); } node* make_node(char l,bool end){ node*n=malloc(sizeof(node)); n->letter=l; n->isEnd=end; for(int i=0;inext[i]=make_empty_tree(); } void delete_tree(tree t){ if(is_empty(t))return; for(int i=0;inext[i]); free(t); } //Casual functions bool is_empty(tree t){ return t==NULL; } bool is_followed(tree t){ int i; for(i=0;inext[i]!=NULL) return true; } return false; } bool is_end(tree t){ return t->isEnd; } int hash(char c){ //needs to check c wether isalpha or '\'' if(c='\'') return 0; return c%32; } //loading functions bool addto_tree(tree t,string s){ //recursive, when called : set isIn to true, and reset index //return wether s is already in t or not bool ret; if(s[0]=='\0'){ ret=t->isEnd; t->isEnd=true; return ret; } if(t->next[hash(s[0])]==NULL){ t->next[hash(s[0])]=make_node(s[0],false); addto_tree2(t->next[hash(s[0])],s+1); return false; } else addto_tree(t->next[hash(s[0])],s+1,isIn); } void addto_tree2(tree t,string s){ //faster than addto_treeused when it is knowned the word is not yet in dictionnary if(s[0]=='\0'){ t->isEnd=true; return; } t->next[hash(s[0])]=make_node(s[0],false); addto_tree2(t->next[hash(s[0])],s+1); } void loadfrom_file(tree,FILE*){} void loadfrom_keyboard(tree){}