#include <iostream> #include <conio.h> using namespace std; struct node { int a; node *left, *right; }; void Show(node *tree); void Push(int x,node *&tree); int main() { node *tree = NULL; int k, num; cout << "Input the number of elements" << endl; cin >> k; for (int i = 0; i < k; i++) { cout << "Input the element" << endl; cin >> num; Push(num,tree); } Show(tree); _getch(); return 0; } void Push(int x,node *&tree) { node *tmp = new node; tmp = tree; node **current = &tree; bool flag = false; if (tree == NULL) { tree = new node; tree->a = x; tree->left = tree->right = NULL; return; } while (!flag) { if (x > tmp->a) { if (tmp->right != NULL) { tmp = tmp->right; } else { /**/ *current = tmp; tmp->right = new node; tmp->right->left = tmp->right->right = NULL; tmp->right->a = x; (*current)->right = tmp->right; flag = true; } } else { if (tmp->left != NULL) { tmp = tmp->left; } else { tmp->left = new node; tmp->left->left = tree->left->right = NULL; tmp->left->a = x; tree = tmp; flag = true; } } } } void Show(node *tree) { if (tree != NULL) { Show(tree->left); cout << tree->a << " "; Show(tree->right); } } I did fill the tree using recursion and now I tried through the cycle .. But there is a problem, I find the place where I need to insert an element but I cannot create a connection.