#include "tree.h" #include //------------------------------------------------------ using namespace std; //------------------------------------------------------ Tree::Tree(void) { head = NULL; } //------------------------------------------------------ void Tree::PrintTree(int i, Node* cur) { if (cur != NULL) { PrintTree(i+1, cur->right); } for (int c=0; c < i; c++) cout << " "; cout << cur << endl; if (cur != NULL) { PrintTree(i+1, cur->left); } } //------------------------------------------------------ void Tree::Insert(int d) { InsertHelper(d, &head); } //------------------------------------------------------ void Tree::InsertHelper(int d, Node** cur) { if (*cur == NULL) { *cur = new Node(d); } else if ((*cur)->data > d) InsertHelper(d, &((*cur)->left)); else InsertHelper(d, &((*cur)->right)); } //------------------------------------------------------