Thank you coder777 and dhayden for your suggestions.
@ coder777 - I was trying to trouble shoot and was wondering if I messed up the implementation of my functions, but I made the suggested changes and kept void. Also I uderstood your implementation, thank you, it helped.
@dhayden - I made some changes in my code and tried to fix the memory leek this way,I believe it might have worked because my code stopped crashing but now I am getting the following errors:
Error
- error LNK2019: unresolved external symbol "public: void __thiscall Tree::TreeSort(int * const,int)" (?TreeSort@Tree@@QAEXQAHH@Z) referenced in function _main
- fatal error LNK1120: 1 unresolved externals
I have done some research where the suggestions were to change some settings, as this did not happen in any other code before I still think that there might be something with my code and with The TreeSort function in particular. What do you think?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
class Tree
{
private:
Tree* root;
public:
int value;
Tree* left;
Tree* right;
void insert(Tree* &root, int newValue);
void printInOrder(Tree* node);
void TreeSort (int list[], int N);
};
void insert(Tree* &root, int newValue)
{
if(root== NULL)
{
root = new Tree;
root-> value = newValue;
root -> left = NULL;
root -> right = NULL;
return;
}
else if(newValue < root->value)
{
insert(root->left,newValue);
}
else
insert(root->right,newValue);
}
void printInOrder(Tree* node)
{
if(node = NULL)
return;
else
{
printInOrder(node->left);
cout<<node->value;
printInOrder(node->right);
}
}
void TreeSort (int list[], int N)
{
Tree* root;
root= NULL;
for (int i=0; i<N; i++)
{
insert(root, list[i]);
}
printInOrder(root);
}
int main(int argc, char** argv[])
{
Tree bst;
int numArray;
cout<<"Enter num to be inserted in array\n";
cin>>numArray;
int* list = new int[numArray];
cout<<"Enter numbers:\n";
for(int i=0; i>numArray; i++)
{
cin>>list[i];
}
bst.TreeSort(list, numArray);
system("pause");
return 0;
}
|