#include <iostream>
#include <String>
#include "Tree.h"
usingnamespace std;
#define NUM 9
int main()
{
int num[NUM] = {4, 2, 7, 3, 6, 8, 0, 112, 9};
int n1,n2,n3;
bool tag = false;
Tree *t = new Tree(5);
for(int i = 0; i < NUM; i++) {
t->insert(num[i]);
}
t->print();
cout << endl << endl;
cout<<"Enter the element to search :";
cin>>n1;
tag=t->search(n1);
if(tag)
cout<<"Found" << endl << endl;
else
cout<<"not found" << endl;
cout<<"Enter the element to remove : ";
cin>>n2;
t->remove(n2);
t->print();
cout << endl << endl;
cout<<"Enter the number to find its occurances : ";
cin>>n3;
int occur=t->count(n3);
cout<<"Number of Occurances is :"<<occur;
delete t;
return 0;
}
I have two problems...first, the remove function isn't working properly and when I try to print() the tree after removing an element, I get a "Process returned -1073741819" message. I realize I have portions of the remove function commented out but it won't compile because remove(val) is not a pointer.
Also, my search function is always returning true...telling me that the element, regardless of what I enter, is found.
In your search function, what if the element is at the beginning or end? In both cases it returns false. And of course it always returns true, you're asking it to search for the element in the left/right of itself, and calling the function of itself ratehr than the left/right. It should search for the given val parameter and call the search function of the left or right.
No, I'm not trying to achieve something different. We were supplied the class itself and just have to implement the remove() function. I also implemented a search function, for my own experience, but am having problems getting the remove() to work properly.