#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> using namespace std; typedef struct node { int num; struct node* left; struct node* right; } node, *tree; void insert(tree& t, int x, int father) { if (t == NULL) { t = (node*)malloc(sizeof(node)); t->num = x; t->left = NULL; t->right = NULL; printf("%d\n", father); return; } else { if (t->num >= x) { insert(t->left, x, t->num); } else { insert(t->right, x, t->num); } } } void inorder(tree t) { if (t == NULL) { return; } inorder(t->left); printf("%d", t->num); inorder(t->right); } int main() { int n; while (scanf("%d", &n) != EOF) { tree root = NULL; while (n--) { int x; scanf("%d", &x); insert(root, x, -1); } } return 0; }