#include #include #include using namespace std; class node { public: int data; node * left = NULL; node * right = NULL; node(int val) { data = val; } }; void insert(node * &root, int val) { if (root == NULL) { root = new node(val); return; } // find the right spot node * current = root; node * parent = root; while (current != NULL) { parent = current; if (val < current->data) { current = current->left; } else { current = current->right; } } // insert to left or right if (val < parent->data) { parent->left = new node(val); } else { parent->right = new node(val); } } void rprint(node * root) { if (root == NULL) return; if (root->right != NULL) { rprint(root->right); } cout << root->data << " "; if (root->left != NULL) { rprint(root->left); } } int main() { node * root = NULL; insert(root, 15); insert(root, 10); insert(root, 72); insert(root, 3); insert(root, 12); insert(root, 61); rprint(root); return 0; }