Language: C

#include<stdio.h>
#define MAX 100005
#define NIL -1
 
int D[MAX],H[MAX],C[MAX];
int n;
int A;
int E,X,Y;
int flag1;

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

Node root;

/*
 p: parent
 l: left-child
 r: right sibling
 */
void print(int);
 
struct Node{ int p, l, r;};
struct Node T[MAX]; // Tree


int getDepth(int u);
void tree(int a);
void hairetu(int);
int parent(int);
int sibling(int);
int degree(int);
int height(int);
/*void preorder(int);
void inorder(int);
void postorder(int);
*/
void hairetu(int a){
  int leaf;
   
  if(getDepth(a) == 0){
    printf("root\n");
  }
// leaf
  else if(T[a].r ==NIL && T[a].l ==NIL){
      printf("leaf\n");
    }
  
  // internal node
  else if(T[a].r!=NIL || T[a].l!= NIL){
    printf("internal node\n"); 
  }
}
 
 
int getDepth(int u){
  int d = 0;
  int i;
  if(u == A) return 0;
  else{
    i = n-1;
    while(1){
      if(u == A) break;
      if(T[i].l == u || T[i].r == u){
    d++;
    u = T[i].p;
      }
      i--;
      if(i<0) i = n-1;
    }
    return d;
  }
   
}
 
int parent(int a){
  int i;
  if(a==A) return -1;
  else {
  for(i=0;i<n;i++){
    if(T[i].l==a || T[i].r == a){
      return T[i].p;
      break;
  }
  }
  }
}
 
int sibling(int b){
  int i;
  if(b==A) return -1;
  else {
    for(i=0;i<n;i++){
      if(T[i].l == b){
    return T[i].r;
      }
      if(T[i].r == b){
    return T[i].l;
      }
    }
  }
}
 
int degree(int d){
  if(T[d].l==-1 && T[d].r == -1){
    return 0;
  }
  else if(T[d].l != -1 && T[d].r != -1){
    return 2;
  }
  else if((T[d].l == -1 && T[d].r != -1) || (T[d].l != -1 && T[d].r == -1)){
    return 1;
  }
  
}
int height(int c){
  int l=0;
  int r=0;
 
  if(T[c].l==-1 && T[c].r == -1){
    return 0;
  }
  if(T[c].l!=-1 && T[c].r != -1){
    l = height(T[c].l)+1;
    r = height(T[c].r)+1;
    if(l<r){
      return r;
    }
    else return l;
  }
  else if(T[c].l==-1&&T[c].r!=-1){
      return height(T[c].r)+1;
    }
  else if(T[c].l!=-1&&T[c].r==-1){
      return height(T[c].l)+1;
    }
}
void print(int u){
  
   
  printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",u,parent(u),sibling(u),degree(u),D[u],height(u));
  hairetu(u);
}

void insert(int k){
  Node y = NULL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NULL;
  z->right = NULL;

  while(x!=NULL){
    y=x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
    z->parent = y;

    if(y==NULL){
      root=z;
    }
    else if(z->key < y->key){
      y->left = z;
    }
    else {
      y->right = z;
    }
  
}

void inorder(Node u){

  if(u != NULL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }


}
void preorder(Node u){

  if(u!=NULL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }  
}
/*
void preorder(int e){
  if(e!=-1){
  if(E<n){
  printf(" %d",T[e].p);
  E++;
  }
  preorder(T[e].l);
  preorder(T[e].r);
  }
}

void inorder(int x){
  if(x!=-1){
  inorder(T[x].l);
  if(X<n){
  printf(" %d",T[x].p);
  X++;
  }
  inorder(T[x].r);
  }
}

void postorder(int y){
  if(y!=-1){
  postorder(T[y].l);
  postorder(T[y].r);
  if(Y<n){
    printf(" %d",T[y].p);
    Y++;
  }
  }
  }*/

main(){
  int i, j, d, v, c, l;
  int t;
  int flag=0;
 
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ) {
    T[i].p = T[i].l = T[i].r = NIL;
  }
 
  for ( i = 0; i < n; i++ ){
    scanf("%d %d %d", &v, &d, &c);
 
    T[v].p = v; 
    insert(v);
    T[v].l = d; 
    T[v].r = c;
   
 
  }
  A = 0;
  for(i=n-1;i>0;i--){
    if(T[i].l==A || T[i].r==A){
      A = T[i].p;   
      flag++;
      if(A == 0){
    break;
      }
    else {
      i = n-1;
    }
    } 
  }

  if(flag == 0){
    A= 0;
  }
  
  
  for(i=0;i<n;i++){
    D[i] = getDepth(i);
  }
 
  // for ( i = 0; i < n; i++ ) print(i);
  //Preorder
  E =0;
  printf("Preorder\n");
  // for(i=0;i<n;i++){
    preorder(T[i].p);
    //}
  printf("\n");
  //inorder
  X =0;
  printf("Inorder\n");
  //  for(i=0;i<n;i++){
    inorder(root);
    // }
  printf("\n");
  //Postorder
  Y =0;
 printf("Postorder\n");
 //  for(i=0;i<n;i++){
    postorder(root);
    // }
  printf("\n");

  return 0;
}

Compiler output:
main.c: In function 'insert':
main.c:155:7: error: implicit declaration of function 'malloc' [-Wimplicit-function-declaration]
  155 |   z = malloc(sizeof(struct node));
      |       ^~~~~~
main.c:2:1: note: include '<stdlib.h>' or provide a declaration of 'malloc'
    1 | #include<stdio.h>
  +++ |+#include <stdlib.h>
    2 | #define MAX 100005
main.c:155:7: warning: incompatible implicit declaration of built-in function 'malloc' [-Wbuiltin-declaration-mismatch]
  155 |   z = malloc(sizeof(struct node));
      |       ^~~~~~
main.c:155:7: note: include '<stdlib.h>' or provide a declaration of 'malloc'
main.c: At top level:
main.c:235:1: error: return type defaults to 'int' [-Wimplicit-int]
  235 | main(){
      | ^~~~
main.c: In function 'main':
main.c:284:18: error: passing argument 1 of 'preorder' makes pointer from integer without a cast [-Wint-conversion]
  284 |     preorder(T[i].p);
      |              ~~~~^~
      |                  |
      |                  int
main.c:193:20: note: expected 'Node' {aka 'struct node *'} but argument is of type 'int'
  193 | void preorder(Node u){
      |               ~~~~~^
main.c:298:5: error: implicit declaration of function 'postorder'; did you mean 'preorder'? [-Wimplicit-function-declaration]
  298 |     postorder(root);
      |     ^~~~~~~~~
      |     preorder