#include "iostream" #include "Cstdio" using namespace Std;struct node{int val; Node *left, *right; Node (int v = 0) {val = V;left = Null;right = NULL;}}; inline void Preorder (Node *head) {//must be added inline to get past, otherwise time limitif (head! = NULL) {printf ("%d", Head->val);p reorder ( Head->left);p reorder (head->right);}} inline void Inorder (Node *head) {if (head! = NULL) {inorder (head->left);p rintf ("%d", head->val); Inorder (head-> right);}} inline void Postorder (Node *head) {if (head! = NULL) {postorder (head->left);p Ostorder (head->right);p rintf ("%d", Head->val);}} inline void Buildtree (Node *&head, const int value) {//use pointer here to refer to if (head = = NULL) {head = new Node (value);} else {if (Head->val < value) {Buildtree (head->right, value);} Elsebuildtree (head->left, value);}} int main () {int N;bool ok = false;while (scanf ("%d", &n)! = EOF) {if (OK) printf ("\ n"); ok = true; Node *root = null;for (int i = 0; i < n; i++) {int tmp;scanf ("%d", &tmp); Buildtree (root, tmp);} printf ("InordeR: "); inorder (Root);p rintf (" \ n ");p rintf (" Preorder: ");p reorder (root);p rintf (" \ n ");p rintf (" Postorder: ");p Ostorder (root);p rintf ("\ n");} return 0;}
1310. Right-heavy Tree