Ive been trying to implement a simple search method for my BST but its always returning false, and when i use cout statements to see where its going, it only ever goes in one case(the < one)-i've tried many variations, but maybe ive been staring at it for too long. hoping a new pair of eyes might shed some light. thanks.
its searching for the customer based off of first and last name, ive overloaded the comparison operators (and checked that they work) to work for the customer objects.
Code:
//a is the customer object in nodes
bool BSTree::search(string x, char y) {
Customer target = Customer(x,y,100);
Node* leafPtr = root;
while(leafPtr!=0){
if(leafPtr->a == target){
cout <<"returning true"<<endl;
return true;
}if(target > leafPtr->a){
cout <<"checking >"<<endl;
leafPtr = leafPtr->right;
}if(target < leafPtr->a){
cout<<"checking <"<<endl;
leafPtr = leafPtr->left;
}
}
return false;//end of while loop
}
heres the test code i was using:
Code:
int main(){
BSTree bst;
bst.insert("H",'h',100);
bst.insert("B",'b',100);
bst.insert("F",'f',100);
bst.insert("I",'i',100);
cout <<"Result"<< bst.search("F",'f')<<endl;
return 0;
}
it keeps giving me false when i tried to check it.
any help is much appreciated.