Language: C++

struct Node {
    int key;
    Node *left,*right,*parent;
};

Node *gRoot,*NIL;

Node *find(Node* u,int value){
    while(u != NIL && value != u->key){
        if(value < u->key) u = u->left;
        else u = u->right;
    }
    return u;
}

void insert(int value){
    Node *y = NIL;
    // 親
    Node *x = gRoot;
    // 自身
    Node *z;
    z = (Node*)malloc(sizeof(Node));
    z->key = value;
    z->left = NIL;
    z->right = NIL;
    
    // rootから自身を挿入する場所を探す
    while(x != NIL){
        // rootから検索
        y = x;
        if(z->key < x->key){
            x = x->left;
        }else{
            x = x->right;
        }
    }
    
    z->parent = y;
    // 親に子を持たせる
    if(y == NIL){
        gRoot = z;
    }else{
        if(z->key < y->key){
            y->left = z;
        }else{
            y->right = z;
        }
    }
}
// 先行順巡回
void preOrder(Node *u){
    if(u == NIL)return;
    printf(" %d",u->key);
    preOrder(u->left);
    preOrder(u->right);
}

// 中間順巡回
void inOrder(Node *u){
    if(u == NIL)return;
    inOrder(u->left);
    printf(" %d",u->key);
    inOrder(u->right);
}

int main(){
    int n,x;
    string com;
    
    cin >> n;
    for(int i = 0;i < n;++i){
        cin >> com;
        if(com[0] == 'f'){
            cin >> x;
            Node *t = find(gRoot,x);
            if(t != NIL) cout << "yes\n";
            else cout << "no\n";
        }
        if(com == "insert"){
            cin >> x;
            insert(x);
        }
        else if(com == "print"){
            inOrder(gRoot);
            cout << "\n";
            preOrder(gRoot);
            cout << "\n";
        }
    }
    return 0;
}



Compiler output:
a.cc: In function 'void insert(int)':
a.cc:22:16: error: 'malloc' was not declared in this scope
   22 |     z = (Node*)malloc(sizeof(Node));
      |                ^~~~~~
a.cc:1:1: note: 'malloc' is defined in header '<cstdlib>'; this is probably fixable by adding '#include <cstdlib>'
  +++ |+#include <cstdlib>
    1 | struct Node {
a.cc: In function 'void preOrder(Node*)':
a.cc:53:5: error: 'printf' was not declared in this scope
   53 |     printf(" %d",u->key);
      |     ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | struct Node {
a.cc: In function 'void inOrder(Node*)':
a.cc:62:5: error: 'printf' was not declared in this scope
   62 |     printf(" %d",u->key);
      |     ^~~~~~
a.cc:62:5: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
a.cc: In function 'int main()':
a.cc:68:5: error: 'string' was not declared in this scope
   68 |     string com;
      |     ^~~~~~
a.cc:70:5: error: 'cin' was not declared in this scope
   70 |     cin >> n;
      |     ^~~
a.cc:72:16: error: 'com' was not declared in this scope
   72 |         cin >> com;
      |                ^~~
a.cc:76:26: error: 'cout' was not declared in this scope
   76 |             if(t != NIL) cout << "yes\n";
      |                          ^~~~
a.cc:77:18: error: 'cout' was not declared in this scope
   77 |             else cout << "no\n";
      |                  ^~~~
a.cc:85:13: error: 'cout' was not declared in this scope
   85 |             cout << "\n";
      |             ^~~~