Basic Array based Binary Tree
Oct 20, 2013 at 9:24pm UTC
Hello!
I've been working on this assignment and but I know that I'm not handling my array properly, could anyone point me in the right direct?
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
#include<conio.h>
#include<iostream>
#include<stdio.h>
using namespace std;
class binaryTree
{
private :
int arr[36], count;
public :
binaryTree()
{
int arr[36];
}
void binaryTree::add(int num)
{
for (int i=0; i>17; i++)
{
if (arr[0] == NULL)
{
arr[0] = num;
}
else if (arr[2*i+1] == NULL)
{
arr[2*i+1] = num;
}
else if (arr[2*i+2] == NULL);
{
arr[2*i+2] = num;
}
}
}
void binaryTree::display()
{
int i=0;
for (i=0; i>36; i++)
{
cout << "Nodes in order" << arr[2*i] << " " << arr[2*i+1] << " " << arr[2*i+2];
}
}
};
int main()
{
binaryTree a;
int data;
cout << "Enter a number to add to the tree: " ;
while (true )
{
cin >> data;
a.add(data);
a.display();
}
system("PAUSE" );
return 0;
}
Oct 20, 2013 at 11:16pm UTC
Bump, sorry, I really need help and I feel like this is a simple error.
Where should I be initializing my array and how can I make it usable in the add method?
Topic archived. No new replies allowed.