#include <iostream>

using namespace std;

struct bst {
    bst* right;
    bst* left;
    bst* parent;
    int val;
};

void add(bst*& root, int x, bst* up = nullptr) {
    if (root == nullptr) {
        bst* newbst = new bst;
        newbst->parent = up;
        newbst->right = nullptr;
        newbst->left = nullptr;
        newbst->val = x;
        root = newbst;
    }
    else {
        if (root->val >= x) {
            add(root->left, x, root);
        }
        else {
            add(root->right, x, root);
        }
    }
}

void inorder(bst* root) {
    if (root) {
        inorder(root->left);
        cout << root->val << " ";
        inorder(root->right);
    }
}



int main() {
    bst* root = nullptr;

    add(root, 12);
    add(root, 8);
    add(root, -3);
    add(root, 5);
    add(root, 6);
    add(root, 18);
    add(root, -4);
    add(root, 0);
    inorder(root);

    return 0;
}