Language: C

#include <stdio.h>

typedef struct node {
  int key;
  struct node *p;
  struct node *left;
  struct node *right;
} Node;

void insert(Node*, Node*);
void print_M(Node*);
void print_P(Node*);


Node T[500000];

int main()
{
  int m,k,i;
  char enter[6];
  Node z;

  T[0].key = -1;
  T[0].left = NULL;
  T[0].right = NULL;
  T[0].p = NULL;

  scanf("%d",&m);
  for(i = 0;i < m;i++){
    scanf("%s %d",enter,&k);
    if(strcmp(enter,"insert") == 0){
      z.key = k;
      z.left = NULL;
      z.right = NULL;
      z.p = NULL;
      insert(T[0],&z);
    }
    else {
      print_M(T[0]);
      print_P(T[0]);
    }

    return 0;
}

void insert(Node T, Node *z)
{
  Node x,y;

  y = NULL; //xの親
  x = T[0]; //Tの根
  while(x != NULL){
    y = x; //親を設定
    if(z.key < x.key) x = x.left; //左の子へ移動
    else x = x.right; //右の子へ移動
  }

  z.p = y;

  if(y == NULL) tree_root = z; //Tが空の場合
  else if(z.key < y.key) y.left = z; //zをyの左の子にする
  else y.right = z; //zをyの右の子にする
}

void print_M(Node now)
{
  if(now.left->key != -1) print_M(now.left->key);
  print_M(now.p->key);
  if(now.right-> != -1) print_P(now.right->key);
}
   
void print_P(Node now)
{
  print_M(now.p->key);
  if(now.left->key != -1) print_M(now.left->key);
  if(now.right->key != NULL) print_P(now.right->key);
}

Compiler output:
main.c: In function 'main':
main.c:31:8: error: implicit declaration of function 'strcmp' [-Wimplicit-function-declaration]
   31 |     if(strcmp(enter,"insert") == 0){
      |        ^~~~~~
main.c:2:1: note: include '<string.h>' or provide a declaration of 'strcmp'
    1 | #include <stdio.h>
  +++ |+#include <string.h>
    2 | 
main.c:36:15: error: incompatible type for argument 1 of 'insert'
   36 |       insert(T[0],&z);
      |              ~^~~
      |               |
      |               Node {aka struct node}
main.c:10:13: note: expected 'Node *' {aka 'struct node *'} but argument is of type 'Node' {aka 'struct node'}
   10 | void insert(Node*, Node*);
      |             ^~~~~
main.c:39:16: error: incompatible type for argument 1 of 'print_M'
   39 |       print_M(T[0]);
      |               ~^~~
      |                |
      |                Node {aka struct node}
main.c:11:14: note: expected 'Node *' {aka 'struct node *'} but argument is of type 'Node' {aka 'struct node'}
   11 | void print_M(Node*);
      |              ^~~~~
main.c:40:16: error: incompatible type for argument 1 of 'print_P'
   40 |       print_P(T[0]);
      |               ~^~~
      |                |
      |                Node {aka struct node}
main.c:12:14: note: expected 'Node *' {aka 'struct node *'} but argument is of type 'Node' {aka 'struct node'}
   12 | void print_P(Node*);
      |              ^~~~~
In file included from /usr/include/stdio.h:34,
                 from main.c:1:
main.c: In function 'insert':
main.c:50:7: error: incompatible types when assigning to type 'Node' {aka 'struct node'} from type 'void *'
   50 |   y = NULL; //xの親
      |       ^~~~
main.c:51:8: error: subscripted value is neither array nor pointer nor vector
   51 |   x = T[0]; //Tの根
      |        ^
main.c:52:11: error: invalid operands to binary != (have 'Node' {aka 'struct node'} and 'void *')
   52 |   while(x != NULL){
      |           ^~
main.c:54:9: error: 'z' is a pointer; did you mean to use '->'?
   54 |     if(z.key < x.key) x = x.left; //左の子へ移動
      |         ^
      |         ->
main.c:54:27: error: incompatible types when assigning to type 'Node' {aka 'struct node'} from type 'struct node *'
   54 |     if(z.key < x.key) x = x.left; //左の子へ移動
      |                           ^
main.c:55:14: error: incompatible types when assigning to type 'Node' {aka 'struct node'} from type 'struct node *'
   55 |     else x = x.right; //右の子へ移動
      |              ^
main.c:58:4: error: 'z' is a pointer; did you mean to use '->'?
   58 |   z.p = y;
      |    ^
      |    ->
main.c:60:8: error: invalid operands to binary == (have 'Node' {aka 'struct node'} and 'void *')
   60 |   if(y == NULL) tree_root = z; //Tが空の場合
      |        ^~
main.c:60:17: error: 'tree_root' undeclared (first use in this function)
   60 |   if(y == NULL) tree_root = z; //Tが空の場合
      |                 ^~~~~~~~~
main.c:60:17: note: each undeclared identifier is reported only once for each function it appears in
main.c:61:12: error: 'z' is a pointer; did you mean to use '->'?
   61 |   else if(z.key < y.key) y.left = z; //zをyの左の子にする
      |            ^
      |            ->
main.c: In function 'print_M':
main.c:67:43: error: incompatible type for argument 1 of 'print_M'
   67 |   if(now.left->key != -1) print_M(now.left->key);
      |                                   ~~~~~~~~^~~~~
      |                                           |
      |                                           int
main.c:65:19: note: expected 'Node' {aka 'struct node'} but argument is of type 'int'
   65 | void print_M(Node now)
      |              ~~~~~^~~
main.c:68:16: error: incompatible type for argument 1 of 'print_M'
   68 |   print_M(now.p->key);
      |           ~~~~~^~~~~
      |                |
      |                int
main.c:65:19: note: expected 'Node' {aka 'struct node'} but argument is of type 'int'
   65 | void print_M(Node now)
      |              ~~~~~^~~
main.c:69:18: error: expected identifier before '!=' token
   69 |   if(now.right-> != -1) print_P(now.right->key);
      |                  ^~
main.c:69:42: error: passing argument 1 of 'print_P' makes pointer from integer without a cast [-Wint-conversion]
   69 |   if(now.right-> != -1) print_P(now.right->key);
      |                                 ~~~~~~~~~^~~~~
      |                                          |
      |                                          int
main.c:12:14: note: expected 'Node *' {aka 'struct node *'} but argument is of type 'int'
   12 | void print_P(Node*);
      |              ^~~~~
main.c: In function 'print_P':
main.c:74:16: error: incompatible type for argument 1 of 'print_M'
   74 |   print_M(now.p->key);
      |           ~~~~~^~~~~
      |                |
      |                int
main.c:65:19: note: expected 'Node' {aka 'struct node'} but argument is of type 'int'
   65 | void print_M(Node now)
      |              ~~~~~^~~
main.c:75:43: error: incompatible type for argument 1 of 'print_M'
   75 |   if(now.left->key != -1) print_M(now.left->key);
      |                                   ~~~~~~~~^~~~~
      |                                           |
      |                                           int
main.c:65:19: note: expected 'Node' {aka 'struct node'} but argument is of type 'int'
   65 | void print_M(Node now)
      |              ~~~~~^~~
main.c:76:21: warning: comparison between pointer and integer
   76 |   if(now.right->key != NULL) print_P(now.right->key);
      |                     ^~
main.c:76:47: error: incompatible type for argument 1 of 'print_P'
   76 |   if(now.right->key != NULL) print_P(now.right->key);
      |                                      ~~~~~~~~~^~~~~
      |                                               |
      |                                               int
main.c:72:19: note: expected 'Node' {aka 'struct node'} but argument is of type 'int'
   72 | void print_P(Node now)
      |              ~~~~~^~~
main.c: In function 'main':
main.c:77:1: error: expected declaration or statement at end of input
   77 | }
      | ^