Binary Search Tree

Binary Search Tree Example Program Download
This is a simple binary search tree program developed in C++.

The entire source code is as below:
#include <iostream>

using namespace std;
typedef struct node
{
    int data;
    struct node *parent;
    struct node *left;
    struct node *right;
};
//declare initial variables
node *root = new node;

//create a binary search tree
int createBST(int value)
{
    root -> data = value;
    root -> left = NULL;
    root -> right = NULL;
    return value;
}

int BST_insert(int value)
{
    node *currentNodePtr = root;
    node *newNode = new node;
    newNode -> data = value;
    bool insertHappened = false;
    while(!insertHappened)
    {
        if (value >= currentNodePtr -> data ) // go to the right of it
        {
            if (currentNodePtr -> right != NULL)
            {
                currentNodePtr = currentNodePtr -> right;
            }
            else
            {
                currentNodePtr -> right = newNode;
                newNode -> left = NULL;
                newNode -> right = NULL;
                insertHappened = true;
            }
        }
        else if (value < currentNodePtr -> data) // go to the left
        {
            if (currentNodePtr -> left != NULL)
            {
                currentNodePtr = currentNodePtr -> left;
            }
            else
            {
                currentNodePtr -> left = newNode;
                newNode -> left = NULL;
                newNode -> right = NULL;
                insertHappened = true;
            }
        }
    }

    return value;
}

void printTree (node *node, int level)
{
    cout << "level: "<<level<< endl;
    cout << node->data << endl;
    level ++;
    if (node->left != NULL)
    {
        cout << "<--" <<endl;
        printTree(node->left,level);
    }
    if (node->right != NULL)
    {
        cout << "-->" <<endl;
        printTree(node->right,level);
    }
}

int main()
{
    cout << "Binary Search Tree Practice Program by Seyong Cho" << endl;
    cout << "create tree = create <val>" << endl;
    cout << "insert to list = insert <val>" << endl;

    while(1)
    {
        string userInput = "";
        int valueInput = 0;
        cin >> userInput;
        if (userInput == "create")
        {
            cin >> valueInput;
            createBST(valueInput);
            printTree(root,0);
        }
        else if (userInput == "insert")
        {
            cin >> valueInput;
            BST_insert(valueInput);
            printTree(root,0);
        }
        else if (userInput == "exit")
        {
            break;
        }
        else{cout<<"invalid command"<<endl;}
    }
    return 0;
}