I have a problems in this code below, it's a part of a program for ordered binary trees. The problem is that when I enter numbers in the input, some elements are just lost and it happens all the times. I looked at the code and can't figure out why that happens. Can you help me out with this? Thanks.
void insert_ord(int number, struct treenode *currentNode){
if(currentNode->flag == 0){
currentNode->number = number;
currentNode->flag = 1;
}
else{
if(number <= currentNode->number){
if(currentNode->left != NULL) insert_ord(number, currentNode->left);
else {
struct treenode *store = (struct treenode *)malloc(sizeof(struct treenode));
currentNode->left = store;
store->number = number;
store->left = store->right = NULL;
store->prev = currentNode;
}
}
if(number > currentNode->number){
if(currentNode->right != NULL) insert_ord(number, currentNode->right);
else {
struct treenode *store = (struct treenode *)malloc(sizeof(struct treenode));
currentNode->right = store;
store->number = number;
store->left = store->right = NULL;
store->prev = currentNode;
}
}
}
}