Language: C++

include<stdio.h>

typedef struct{
  int id;
  int left;
  int right;
  int p;
  int s;
  int deg;
  int dep;
  int h;
}Tree;

int depth(int);
int height(int, int);

Tree data[100];

int main()
{
  int i, n, j, flag, count=0;
  char *str[] = {"root", "internal node", "leaf"};
  Tree temp;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d%d%d", &data[i].id, &data[i].left, &data[i].right);

    if(data[i].left == -1 && data[i].right == -1){
      data[i].deg = 0;
      /* data[i].h = 0; */
    }
    else if(data[i].left == -1 || data[i].right == -1) data[i].deg = 1;
    else data[i].deg = 2;
  }

/* parent?????? */
  for(i = 0; i < n; i++){
    if(data[i].left == -1 && data[i].right == -1) continue;
    for(j = 0; j < n; j++){
      if(j == 0) data[j].p = -1;
      else if(data[j].id == data[i].left || data[j].id == data[i].right) \
data[j].p = data[i].id;
    }
  }
/* sibling */
  for(i = 0; i < n; i++){
    if(data[i].p == -1) data[i].s = -1;
    if(data[i].left != -1 && data[i].right != -1){
      for(j = 0; j < n; j++){
        if(data[j].id == data[i].left) data[j].s = data[i].right;
        else if(data[j].id == data[i].right) data[j].s = data[i].left;
      }
    }
  }

  //height
  for(i = n-1; i >= 0; i--){
    data[i].h = height(data[i].left, data[i].right);
  }

/* ?????????sort */
  flag = 1;
  j = 0;
  while(flag){
    flag = 0;
    for(i = n-1; i >= 1; i--){
      if(data[i].id < data[i-1].id){
        temp = data[i-1];
        data[i-1] = data[i];
        data[i] = temp;
        flag = 1;
        j++;
      }
    }
  }

  //depth
  for(i = 0; i < n; i++){
    data[i].dep = depth(data[i].p);
  }

  for(i = 0; i < n; i++){
    printf("node %d: ", data[i].id);
    printf("parent = %d, ", data[i].p);
    printf("sibling = %d, ", data[i].s);
    printf("degree = %d, ", data[i].deg);
    printf("depth = %d, ", data[i].dep);
    printf("height = %d, ", data[i].h);

    if(data[i].p == -1 && data[i].deg != 0) printf("%s", str[0]);
    else if(data[i].p != -1 && data[i].deg != 0) printf("%s", str[1]);
    else if(data[i].p != -1 && data[i].deg == 0) printf("%s", str[2]);

    printf("\n");
  }

  return 0;
}

int depth(int p)
{
  int count=0;

  if(p == -1) return 0;
  else{
    count++;
    return count + depth(data[p].p);
  }
}

int height(int l, int r)
{
  int count=0;

  if(l == -1 && r == -1) return 0;
  else if(l == -1 && r != -1) return data[r].h + count;
  else if(l != -1 && r == -1) return data[l].h + count;

  else if(l != -1 && r != -1){
    count++;
    if(data[l].h == data[r].h) return data[l].h + count;
    else if(data[l].h > data[r].h) return data[l].h + count;
    else if(data[l].h < data[r].h) return data[r].h + count;
  }
}

Compiler output:
a.cc:1:1: error: 'include' does not name a type
    1 | include<stdio.h>
      | ^~~~~~~
a.cc:12:2: error: 'Tree' does not name a type
   12 | }Tree;
      |  ^~~~
a.cc:17:1: error: 'Tree' does not name a type
   17 | Tree data[100];
      | ^~~~
a.cc: In function 'int main()':
a.cc:22:18: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
   22 |   char *str[] = {"root", "internal node", "leaf"};
      |                  ^~~~~~
a.cc:22:26: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
   22 |   char *str[] = {"root", "internal node", "leaf"};
      |                          ^~~~~~~~~~~~~~~
a.cc:22:43: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
   22 |   char *str[] = {"root", "internal node", "leaf"};
      |                                           ^~~~~~
a.cc:23:3: error: 'Tree' was not declared in this scope
   23 |   Tree temp;
      |   ^~~~
a.cc:25:3: error: 'scanf' was not declared in this scope
   25 |   scanf("%d", &n);
      |   ^~~~~
a.cc:28:22: error: 'data' was not declared in this scope
   28 |     scanf("%d%d%d", &data[i].id, &data[i].left, &data[i].right);
      |                      ^~~~
a.cc:40:8: error: 'data' was not declared in this scope
   40 |     if(data[i].left == -1 && data[i].right == -1) continue;
      |        ^~~~
a.cc:42:18: error: 'data' was not declared in this scope
   42 |       if(j == 0) data[j].p = -1;
      |                  ^~~~
a.cc:43:15: error: 'data' was not declared in this scope
   43 |       else if(data[j].id == data[i].left || data[j].id == data[i].right) \
      |               ^~~~
a.cc:49:8: error: 'data' was not declared in this scope
   49 |     if(data[i].p == -1) data[i].s = -1;
      |        ^~~~
a.cc:50:8: error: 'data' was not declared in this scope
   50 |     if(data[i].left != -1 && data[i].right != -1){
      |        ^~~~
a.cc:60:5: error: 'data' was not declared in this scope
   60 |     data[i].h = height(data[i].left, data[i].right);
      |     ^~~~
a.cc:69:10: error: 'data' was not declared in this scope
   69 |       if(data[i].id < data[i-1].id){
      |          ^~~~
a.cc:70:9: error: 'temp' was not declared in this scope
   70 |         temp = data[i-1];
      |         ^~~~
a.cc:81:5: error: 'data' was not declared in this scope
   81 |     data[i].dep = depth(data[i].p);
      |     ^~~~
a.cc:85:25: error: 'data' was not declared in this scope
   85 |     printf("node %d: ", data[i].id);
      |                         ^~~~
a.cc:85:5: error: 'printf' was not declared in this scope
   85 |     printf("node %d: ", data[i].id);
      |     ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | include<stdio.h>
a.cc: In function 'int depth(int)':
a.cc:109:26: error: 'data' was not declared in this scope
  109 |     return count + depth(data[p].p);
      |                          ^~~~
a.cc: In function 'int height(int, int)':
a.cc:118:38: error: 'data' was not declared in this scope
  118 |   else if(l == -1 && r != -1) return data[r].h + count;
      |                                      ^~~~
a.cc:119:38: error: 'data' was not declared in this scope
  119 |   else if(l != -1 && r == -1) return data[l].h + count;
      |                                      ^~~~
a.cc:123:8: error: 'data' was not declared in this scope
  123 |     if(data[l].h == data[r].h) return data[l].h + count;
      |        ^~~~