I have a class of "stocks" which include a company name, company symbol and stock price. I am building a binary tree of these stocks. I am supposed to be able to enter a stock symbol and pull either the company name or the stock price, depending on the option chosen from the switch.
I have traced this several times and what happens is once it finds the stock with that symbol, it completes it's current recursive iteration. then when it "bubbles up" to the previous recursive call, drops into the item < root->data and goes up another level and drops into the root->data == 0. This sets temp to Null and returns Null everytime. Can some one please help, and let me know if you need anymore of the code. Thanks in advance!
Below is my call from main, from the switch:
1 2 3 4 5 6 7 8 9 10 11 12
case 1:
{
cout<<"Enter the Company Symbol: ";
cin >> sTemp; //string
temp.setSymbol(sTemp); //temp is stock obj
ptrTemp = (Co.search(temp)); //ptrTemp is ptr to stock, Co is BinaryTree obj
if (ptrTemp == NULL)
cout <<"Not Found!"<<endl;
else
cout << ptrTemp->getName();
break;
}
These two below are my Binary Tree seach functions:
Do you have operator== and operator< defined properly for "stock obj"? It looks like your intention in the tree code would be to just compare by the symbol, which isn't necessarily what you would want for a general operator== and operator<. Although, I don't know what setSymbol() does. I would assume you have company name and stock symbol as strings. Does your temp object just have the symbol set and nothing else? Anyway, nothing else is standing out, but it is late.
Oh, no reason to pass root by reference, unless you need to change it.