lundi 23 février 2015

i have problem comparing node elements with key in dictionary tree


guys i have to make a dictionary tree , but i still have problem running it ,what i need is to insert into binary tree .code is below .I have problem to compare two elements , it compares only the element in the paramaeters ,rather i have to compare key each time with the tree node . thanks in advance for any help.



typedef struct node * tree_ptr;
struct node {
Key_Type element;
tree_ptr left;
tree_ptr right;
};

struct table {
tree_ptr head; // points to the head of the tree

};

Table initialize_table() {
Table tt = malloc(sizeof (tree_ptr));
tt->head = NULL;
return tt;
}

Table insert(Key_Type key ,Table temp ) {
// int cmp = strcmp(key,temp->head);
tree_ptr t = malloc(sizeof (*t));
if(t) {
t->left = t->right = NULL;
t->element = key;
//if(t->element == strdup(key)) {
if(temp->head==NULL) {
temp = malloc(sizeof (*temp));
//temp->head = malloc(sizeof( *temp));
temp->head = t;
// temp->head->left = temp->head->right = NULL;
printf("to here\n");
}
else
//if(t->element = strdup("one"))
printf("%s ",temp->head->element);
// temp->head->left = insert(key, temp->head->left);
// printf("%d \n",strcmp(key,t->element));
// int cmp = strcmp(key,temp->head->element);


}
return temp;


}





Aucun commentaire:

Enregistrer un commentaire