#include <iostream> using namespace std; typedef struct Treenode { struct Treenode* left; struct Treenode* right; int val; }*Tree; void insert(Tree &root, int x) { if (!root) { root = (Treenode*) malloc(sizeof(Treenode)); root->left = nullptr; root->right = nullptr; root->val = x; return; } if (root->val==x) return; else if (root->val > x) insert(root->left, x); else insert(root->right, x); } void preorder(Tree& root) { if (root) { cout << root->val << " "; preorder(root->left); preorder(root->right); } } void inorder(Tree& root) { if (root) { inorder(root->left); cout << root->val << " "; inorder(root->right); } } void postorder(Tree& root) { if (root) { postorder(root->left); postorder(root->right); cout << root->val << " "; } } int main() { int n; while (cin >> n) { int x; Treenode* root = nullptr; while (n--) { cin >> x; insert(root, x); } preorder(root); cout<<endl; inorder(root); cout<<endl; postorder(root); cout<<endl; free(root); } }