this my the code
Code:
#define N 3
typedef struct tree {
int value;
struct tree **sons; // array of pointers
} tree;
tree * what1(){
int i;
tree *temp = (tree *)malloc(sizeof(tree));
if(!temp) exit(1);
temp->value=0;
temp->sons = (tree **)malloc(N * sizeof(tree *));
if(!temp->sons) exit(1);
for(i=0; i<N; i++)
temp->sons[i]=NULL;
return temp;
}
void what2(tree *root, char *text){
if(!(*text)){
root->value++;
return;
}
if(!root->sons[*text-'a'])
root->sons[*text-'a']= what1();
what2(root->sons[*text-'a'],text+1);
}
void what3(tree *root){
int i;
if(!root) return;
printf("%d ",root->value);
for(i=0; i<N; i++)
what3(root->sons[i]);
}
void main(){
tree *root= what1();
int i;
char *text[]={"aac","aa","bbb","aac","aa","aabc","a"},
stack[80]={0};
for(i=0; i<7; i++)
what2(root,text[i]);
what3(root);
putchar('\n');
}