Language: C++

import java.io.*;
import java.util.StringTokenizer;
   
class Main{
   
static final PrintWriter out=new PrintWriter(System.out);

class binarySearchTree{

static class Node{
int id;
Node p;
Node l;
Node r;
int deg;
Node(int id){
this.id=id; this.p=null; this.l=null; this.r=null; this.deg=0;
}
}

Node root;

binarySearchTree(){
root=null;
}

private static void insert(int v){
if(root==null) root=new Node(v);
else __insert(new Node(v));
}

private static void __insert(Node z){
Node x=root;
Node y=null;
while(x!=null){
y=x;
if(z.id<x.id) x=x.l;
else x=x.r;
}
z.p=y;
if(z.id<y.id) y.l=z;
else y.r=z;
y.deg++;
}

static void print(){
inorder(root.id);
out.println();
preorder(root.id);
out.println();
}

static void preorder(int now){
if(now<0) return;
out.print(" "+now);
preorder(ns[now].l.id);
preorder(ns[now].r.id);
}
 
static void inorder(int now){
if(now<0) return;
inorder(ns[now].l.id);
out.print(" "+now);
inorder(ns[now].r.id);
}
 
static void postorder(int now){
if(now<0) return;
postorder(ns[now].l.id);
postorder(ns[now].r.id);
out.print(" "+now);
}
}

public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
binarySearchTree tree=new binarySearchtree();
int num=Integer.parseInt(br.readLine());
for(int i=0;i<num;i++){
st=new StringTokenizer(br.readLine());
String command=st.nextToken();
int n=Integer.parseInt(st.nextToken());
if("insert".equals(command)) tree.insert(n);
else tree.print();
}
out.flush();
}
}

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.io.*;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import java.util.StringTokenizer;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:8: error: 'final' does not name a type
    6 | static final PrintWriter out=new PrintWriter(System.out);
      |        ^~~~~
a.cc:12:6: error: field 'p' has incomplete type 'Main::binarySearchTree::Node'
   12 | Node p;
      |      ^
a.cc:10:14: note: definition of 'class Main::binarySearchTree::Node' is not complete until the closing brace
   10 | static class Node{
      |              ^~~~
a.cc:13:6: error: field 'l' has incomplete type 'Main::binarySearchTree::Node'
   13 | Node l;
      |      ^
a.cc:10:14: note: definition of 'class Main::binarySearchTree::Node' is not complete until the closing brace
   10 | static class Node{
      |              ^~~~
a.cc:14:6: error: field 'r' has incomplete type 'Main::binarySearchTree::Node'
   14 | Node r;
      |      ^
a.cc:10:14: note: definition of 'class Main::binarySearchTree::Node' is not complete until the closing brace
   10 | static class Node{
      |              ^~~~
a.cc:21:1: error: expected ';' at end of member declaration
   21 | Node root;
      | ^~~~
      |     ;
a.cc:21:6: error: 'root' does not name a type
   21 | Node root;
      |      ^~~~
a.cc:27:8: error: expected ':' before 'static'
   27 | private static void insert(int v){
      |        ^~~~~~~
      |        :
a.cc:32:8: error: expected ':' before 'static'
   32 | private static void __insert(Node z){
      |        ^~~~~~~
      |        :
a.cc:32:30: error: 'Node' is not a type
   32 | private static void __insert(Node z){
      |                              ^~~~
a.cc:73:2: error: expected ';' after class definition
   73 | }
      |  ^
      |  ;
a.cc:75:7: error: expected ':' before 'static'
   75 | public static void main(String[] args) throws IOException{
      |       ^~~~~~~
      |       :
a.cc:75:25: error: 'String' has not been declared
   75 | public static void main(String[] args) throws IOException{
      |                         ^~~~~~
a.cc:75:34: error: expected ',' or '...' before 'args'
   75 | public static void main(String[] args) throws IOException{
      |                                  ^~~~
a.cc:75:38: error: expected ';' at end of member declaration
   75 | public static void main(String[] args) throws IOException{
      |                                      ^
      |                                       ;
a.cc:75:40: error: 'throws' does not name a type
   75 | public static void main(String[] args) throws IOException{
      |                                        ^~~~~~
a.cc:89:2: error: expected ';' after class definition
   89 | }
      |  ^
      |  ;
a.cc: In constructor 'Main::binarySearchTree::Node::Node(int)':
a.cc:17:6: error: request for member 'id' in '(Main::binarySearchTree::Node*)this', which is of pointer type 'Main::binarySearchTree::Node*' (maybe you meant to use '->' ?)
   17 | this.id=id; this.p=null; this.l=null; this.r=null; this.deg=0;
      |      ^~
a.cc:17:18: error: request for member 'p' in '(Main::binarySearchTree::Node*)this', which is of pointer type 'Main::binarySearchTree::Node*' (maybe you meant to use '->' ?)
   17 | this.id=id; this.p=null; this.l=null; this.r=null; this.deg=0;
      |                  ^
a.cc:17:20: error: 'null' was not declared in this scope
   17 | this.id=id; this.p=null; this.l=null; this.r=null; this.deg=0;
      |                    ^~~~
a.cc:17:31: error: request for member 'l' in '(Main::binarySearchTree::Node*)this', which is of pointer type 'Main::binarySearchTree::Node*' (maybe you meant to use '->' ?)
   17 | this.id=id; this.p=null; this.l=null; this.r=null; this.deg=0;
      |                               ^
a.cc:17:44: error: request for member 'r' in '(Main::binarySearchTree::Node*)this', which is of pointer type 'Main::binarySearchTree::Node*' (maybe you meant to use '->' ?)
   17 | this.id=id; this.p=null; this.l=null; this.r=null; this.deg=0;
      |                                            ^
a.cc:17:57: error: request for member 'deg' in '(Main::binarySearchTree::Node*)this', which is of pointer type 'Main::binarySearchTree::Node*' (maybe you meant to use '->' ?)
   17 | this.id=id; this.p=null; this.l=null; this.r=null; this.deg=0;
      |                                                         ^~~
a.cc: In constructor 'Main::binarySearchTree::binarySearchTree()':
a.cc:24:1: error: 'root' was not declared in this scope
   24 | root=null;
      | ^~~~
a.cc:24:6: error: 'null' was not declared in this scope
   24 | root=null;
      |      ^~~~
a.cc: In static member function 'static void Main::binarySearchTree::insert(int)':
a.cc:28:4: error: 'root' was not declared in this scope
   28 | if(root==null) root=new Node(v);
      |    ^~~~
a.cc:28:10: error: 'null' was not declared in this scope
   28 | if(root==null) root=new Node(v);
      |          ^~~~
a.cc:28:25: error: expected type-specifier before 'Node'
   28 | if(root==null) root=new Node(v);
      |                         ^~~~
a.cc:29:19: error: expected type-specifier before 'Node'
   29 | else __insert(new Node(v));
      |                   ^~~~
a.cc: In static member function 'static void Main::binarySearchTree::__insert(int)':
a.cc:33:6: error: expected ';' before 'x'
   33 | Node x=root;
      |      ^
a.cc:34:6: error: expected ';' before 'y'
   34 | Node y=null;
      |      ^
a.cc:35:7: error: 'x' was not declared in this scope
   35 | while(x!=null){
      |       ^
a.cc:35:10: error: 'null' was not declared in this scope
   35 | while(x!=null){
      |          ^~~~
a.cc:36:1: error: 'y' was not declared in this scope
   36 | y=x;
      | ^
a.cc:37:6: error: request for member 'id' in 'z', which is of non-class type 'int'
   37 | if(z.id<x.id) x=x.l;
      |      ^~
a.cc:40:3: error: request for member 'p' in 'z', which is of non-class type 'int'
   40 | z.p=y;
      |   ^
a.cc:40:5: error: 'y' was not declared in this scope
   40 | z.p=y;
      |     ^
a.cc:41:6: error: request for member 'id' in 'z', which is of non-class type 'int'
   41 | if(z.id<y.id) y.l=z;
      |      ^~
a.cc: In static member function 'static void Main::binarySearchTree::print()':
a.cc:47:9: error: 'root' was not declared in this scope
   47 | inorder(root.id);
      |         ^~~~
a.cc:48:1: error: 'out' was not declared in this scope
   48 | out.println();
      | ^~~
a.cc: In static member function 'static void Main::binarySearchTree::preorder(int)':
a.cc:55:1: error: 'out' was not declared in this scope
   55 | out.print(" "+now);
      | ^~~
a.cc:56:10: error: 'ns' was not declared in this scope
   56 | preorder(ns[now].l.id);
      |          ^~
a.cc: In static member function 'static void Main::binarySearchTree::inorder(int)':
a.cc:62:9: error: 'ns' was not declared in this scope
   62 | inorder(ns[now].l.id);
      |         ^~
a.cc:63:1: error: 'out' was not declared in this scope
   63 | out.print(" "+now);
      | ^~~
a.cc: In static member function 'static void Main::binarySearchTree::postorder(int)':
a.cc:69:11: error: 'ns' was not declared in this scope
   69 | postorder(ns[now].l.id);
      |           ^~
a.cc:71:1: error: 'out' was not declared in this scope
   71 | out.print(" "+now);
      | ^~~