I am tasked with storing a binary tree within a vector. Within each node is stored an int ID, int Age, and a string name.
The nodes are stored and organized within the vector by ID.
When storing the binary tree within a vector, I am using the algorithm 2i and 2i+1 to dictate a node's left and right child respectively.
I have managed to create an insert method that I believe satisfies these conditions, however for some reason, when attempting to print the values of my vector, I appear to get negative values. For this particular example, I insert the following values
50 21 Tim
75 22 Steve
30 40 Eric
20 35 Mary
100 60 Judy
After inserting these four values, I attempt to use my find() method to find Eric, in which my program returns "Not Found!"
I run my report() function to find that all the values stored within my vector are large negative valued IDs.
Is there a particular reason for this? Find() Report()
Here is my code.
#include "BinaryTree.h"
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int index = 0;
struct Node
{
    int ID;
    int age;
    string name;
    Node()
    {
    }
    Node(int id, int Age, string nm)
    {
        this->ID = id;
        this->age = Age;
        this->name = nm;
    }
};
vector<Node> binaryTree(30);
BST::BST()
{
}
void BST::start()
{
    int choice;
    cout << "What would you like to do?" << endl;
    cout << "1. Add a node to the tree" << endl;
    cout << "2. Delete a node from the tree" << endl;
    cout << "3. Find a node in the tree" << endl;
    cout << "4. Report the contents of the tree" << endl;
    cout << "5. Exit program" << endl;
    cin >> choice;
    if (choice == 1)
    {
        insert();
    }
    if (choice == 2)
    {
        Delete();
    }
    if (choice == 3)
    {
        find();
    }
    if (choice == 4)
    {
        report();
    }
}
void BST::insert()
{
    int ID;
    int AGE;
    string NAME;
    int root = 1;
    bool success = false;
    cout << "Please enter the ID number, age and name:" << endl;
    do
    {
        cin >> ID >> AGE >> NAME;
    } while (ID < 0);
    Node *tree = new Node(ID, AGE, NAME);
    if (index = 0)
    {
        binaryTree[1] = *tree;
    }
    if (index > 0)
    {
        do
        {
            if (tree->ID > binaryTree.at(root).ID)
            {
                root = 2 * root + 1;
            }
            if (tree->ID < binaryTree.at(root).ID)
            {
                root = 2 * root;
            }
            if (binaryTree.at(root).ID == NULL)
            {
                binaryTree.at(root) = *tree;
                success = true;
            }
        } while (!success);
    }
    index++;
    delete tree;
    start();
}
void BST::Delete()
{
    int input_id;
    cout << "What is the ID of the person to be deleted" << endl;
    cin >> input_id;
    for (unsigned int i = 0; i < binaryTree.size(); i++)
    {
        if (input_id == binaryTree.at(i).ID)
            binaryTree.erase(binaryTree.begin() + i);
    }
    cout << " " << endl;
    start();
}
void BST::find()
{
    int key;
    bool found = 0;
    cout << "What's the ID?" << endl;
    cout << " " << endl;
    cin >> key;
    for (unsigned int i = 0; i < binaryTree.size(); i++)
    {
        if (binaryTree.at(i).ID == key)
        {
            cout << "The ID is " << binaryTree.at(i).ID << endl;
            cout << "The age ID " << binaryTree.at(i).age << endl;
            cout << "The name is " <<binaryTree.at(i).name << endl;
            cout << " " << endl;
            found = true;
        }
        if (found == false)
        {
            cout << "Not found." << endl;
            cout << "" << endl;
            break;
        }
    }
    start();
}
void BST::report()
{
    cout << "The contents of the tree are" << endl;
    cout << " " << endl;
    for (unsigned int i = 0; i < binaryTree.size(); i++)
    {
        int level = 0;
        if (i == 0) level = 0;
        if (i == 1 || i == 2) level = 1;
        if (i >= 3 && i <= 6) level = 2;
        if (i >= 7 && i <= 14) level = 3;
//TODO complete list
        cout << binaryTree.at(i).ID << " " << binaryTree.at(i).age << " " << &binaryTree.at(i).name << " " << level << endl;
    }
}
Would appreciate the suggestions/help!
Thanks!
 
    