Problems:
1) Everything in the Set::Node and Queue::Node classes are private because there is no
public:
marker. Classes default to private unless you explicitly put the public marker there.
2) Set's destructor is trying to call
koolaid
... but koolaid is not a member of Set.
3) This line in set.h:
else if (item>t->item) t-right = insert(t->right, item);
t-right
is supposed to be
t->right
4) In Set::print:
1 2 3 4
|
void print(Node* currentNode, ofstream& output, int level) //PRINT
{
Queue<ItemType>* printMe = new Queue<ItemType>();
printMe->append(currentNode);
|
'currentNode' is of type
Node*
printMe->append()'s parameter is of type
ItemType
You cannot convert a
Node*
to an
ItemType
. You probably meant to do
append(currentNode->item);
5) Just below that you have a similar problem:
currentNode = printMe->pop();
pop() returns an ItemType, not a Node*. Probably meant to do:
currentNode->item = printMe->pop();
6) Just below that... same problem as #4 two more times:
1 2
|
if (currentNode->left != NULL) printMe->append(currentNode->left);
if (currentNode->right != NULL) printMe->append(currentNode->right);
|
7) Similar type confusion in Set::remove:
t->item = findMin(t->right);
t->item is a
ItemType
but findMin returns a
Node*
.
Did you mean
t = findMin(t->right);
?
8) Set::balance has to return a value:
1 2
|
Node* balance(Node* t)
{} // <- you're not returning anything
|
----------------------
After all those changes... it compiles.
TIPS:
-------------------------------------
1) Name your functions appropriately. Getting cute makes it harder for people to understand what's going on. "koolaid" is a terrible, terrible function name.
2) Compile more often and solve these problems as they come up. Don't try to code everything blind (going a long time without compiling) or else you'll end up with what happened here: a page of errors and you get overwhelmed.
3) A good IDE will tell you exactly what line the error is on. Most let you double click right on the error message and they'll jump you right to the line that has the problem. With that you probably could have been able to figure all these out yourself.
4) There is no reason for the 'koolaid' function to exist. It destroys the object... so just do that stuff in the destructor. Outside code should not have to call that function... if it's in the destructor it will run automatically when the node is destroyed.
Can I compare strings with > or < ? |
Yes.