I am trying to create a tree that will represent an array of strings given the array of strings, the starting node, and the size of the array of strings.
Code:
e.g calling initialize tree with {"ab","ac","ace","act","aco","bd","b"} should be
a b
/ \ |
c b d
/|\
e t o
I am getting warnings complaining about assignment from incompatible pointer types, but I don't understand where I went wrong.
Code:
typedef struct{
struct struct_node *child_next;
struct struct_node *child_start;
char data;
int is_end;
}struct_node;
void initialize_tree(struct_node *tree, char **text, int size){
void add_element(struct_node *tree, char *text, int i){
if(text[i] == '\0')
tree->is_end = 1;
else if(tree->data == text[i] && tree->child_start != NULL){
tree = tree->child_start;
add_element(tree, text, ++i);
}else if(tree->data != text[i] && tree->child_next != NULL){
tree = tree->child_next;
add_element(tree, text, ++i);
}else if(tree->child_next == NULL
|| (tree->data == text[i] && tree->child_start == NULL)){
tree->child_next = malloc(sizeof(struct_node));
tree = tree->child_next;
tree->child_start = tree;
tree->data = text[i];
add_element(tree, text, ++i);
}
}
struct struct_node *root = tree;
int i = 0;
while(i < size){
add_element(tree, text[i], 0);
tree = root;
i++;
}
};