Language: C

void degree(int);
int height(int);
data A[25];
int B[25];
int main(){
  int N,i,id,l,r,root;

  scanf("%d",&N);

  for(i=0;i<N;i++) {
    A[i].parent=NIL;
    A[i].sibling=NIL;
  }
    for(i=0;i<N;i++){
    scanf("%d%d%d",&id,&l,&r);
    
    A[i].left=l;
    A[i].right=r;
    if(l!=NIL) A[l].parent=id;
    if(r!=NIL) A[r].parent=id;
    }
    for(i=0;i<N;i++){
      if(A[i].parent==-1) root=i;
	}
    printf("%d\n",root);
    preparse(root);
  sibling(root,A[root].right,A[root].left);
  degree(root);
  height(root);
  
  for(i=0;i<N;i++){ printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,A[i].parent,A[i].sibling,A[i].degree,A[i].depth,A[i].height);  
    if(A[i].parent==NIL) printf("root\n");
    else if(A[i].right==NIL&&A[i].left==NIL) printf("leaf\n");
    else if((A[i].right!=NIL&&A[i].left==NIL)||(A[i].right==NIL&&A[i].left!=NIL)||(A[i].right!=NIL&&A[i].left!=NIL))printf("internal node\n");
  
  }
  return 0;
}

void preparse(int u){
  static int count;
 
  if(u==NIL) return;

  A[u].depth=count;
  count++;
  preparse(A[u].left);
  preparse(A[u].right);
  count--;
}

void sibling(int u,int r,int l){
  int i;

  if(u==NIL) return;
  if(A[u].left!=NIL && A[u].right!=NIL) {
    A[l].sibling=A[u].right;   
    A[r].sibling=A[u].left;
  }

  sibling(A[u].left,A[l].right,A[l].left);
  sibling(A[u].right,A[r].right,A[r].left);
  
}
  
void degree(int u){
  if(u==NIL) return;
  if(A[u].left!=NIL && A[u].right!=NIL) A[u].degree=2;
  else if((A[u].left==NIL && A[u].right!=NIL) || (A[u].left!=NIL && A[u].right==NIL)) A[u].degree=1;
  else A[u].degree=0;

  degree(A[u].left);
  degree(A[u].right);
}

int height(int u){
  int h1=0,h2=0;
  if(A[u].left!=NIL) h1=height(A[u].left)+1;
  if(A[u].right!=NIL) h2=height(A[u].right)+1;

if(h1>h2) B[u]=h1;
      else B[u]=h2;
 A[u].height=B[u];
 
 return B[u]; 
}

Compiler output:
main.c:3:1: error: unknown type name 'data'
    3 | data A[25];
      | ^~~~
main.c: In function 'main':
main.c:8:3: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
    8 |   scanf("%d",&N);
      |   ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | void degree(int);
main.c:8:3: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
    8 |   scanf("%d",&N);
      |   ^~~~~
main.c:8:3: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:11:9: error: request for member 'parent' in something not a structure or union
   11 |     A[i].parent=NIL;
      |         ^
main.c:11:17: error: 'NIL' undeclared (first use in this function)
   11 |     A[i].parent=NIL;
      |                 ^~~
main.c:11:17: note: each undeclared identifier is reported only once for each function it appears in
main.c:12:9: error: request for member 'sibling' in something not a structure or union
   12 |     A[i].sibling=NIL;
      |         ^
main.c:17:9: error: request for member 'left' in something not a structure or union
   17 |     A[i].left=l;
      |         ^
main.c:18:9: error: request for member 'right' in something not a structure or union
   18 |     A[i].right=r;
      |         ^
main.c:19:20: error: request for member 'parent' in something not a structure or union
   19 |     if(l!=NIL) A[l].parent=id;
      |                    ^
main.c:20:20: error: request for member 'parent' in something not a structure or union
   20 |     if(r!=NIL) A[r].parent=id;
      |                    ^
main.c:23:14: error: request for member 'parent' in something not a structure or union
   23 |       if(A[i].parent==-1) root=i;
      |              ^
main.c:25:5: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
   25 |     printf("%d\n",root);
      |     ^~~~~~
main.c:25:5: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:25:5: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:25:5: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:26:5: error: implicit declaration of function 'preparse' [-Wimplicit-function-declaration]
   26 |     preparse(root);
      |     ^~~~~~~~
main.c:27:3: error: implicit declaration of function 'sibling' [-Wimplicit-function-declaration]
   27 |   sibling(root,A[root].right,A[root].left);
      |   ^~~~~~~
main.c:27:23: error: request for member 'right' in something not a structure or union
   27 |   sibling(root,A[root].right,A[root].left);
      |                       ^
main.c:27:37: error: request for member 'left' in something not a structure or union
   27 |   sibling(root,A[root].right,A[root].left);
      |                                     ^
main.c:31:111: error: request for member 'parent' in something not a structure or union
   31 |   for(i=0;i<N;i++){ printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,A[i].parent,A[i].sibling,A[i].degree,A[i].depth,A[i].height);
      |                                                                                                               ^
main.c:31:123: error: request for member 'sibling' in something not a structure or union
   31 |   for(i=0;i<N;i++){ printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,A[i].parent,A[i].sibling,A[i].degree,A[i].depth,A[i].height);
      |                                                                                                                           ^
main.c:31:136: error: request for member 'degree' in something not a structure or union
   31 |   for(i=0;i<N;i++){ printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,A[i].parent,A[i].sibling,A[i].degree,A[i].depth,A[i].height);
      |                                                                                                                                        ^
main.c:31:148: error: request for member 'depth' in something not a structure or union
   31 |   for(i=0;i<N;i++){ printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,A[i].parent,A[i].sibling,A[i].degree,A[i].depth,A[i].height);
      |                                                                                                                                                    ^
main.c:31:159: error: request for member 'height' in something not a structure or union
   31 |   for(i=0;i<N;i++){ printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,A[i].parent,A[i].sibling,A[i].degree,A[i].depth,A[i].height);
      |                                                                                                                                                               ^
main.c:32:12: error: request for member 'parent' in something not a structure or union
   32 |     if(A[i].parent==NIL) printf("root\n");
      |            ^
main.c:33:17: error: request for member 'right' in something not a structure or union
   33 |     else if(A[i].right==NIL&&A[i].left==NIL) printf("leaf\n");
      |                 ^
main.c:33:34: error: request for member 'left' in something not a structure or union
   33 |     else if(A[i].right==NIL&&A[i].left==NIL) printf("leaf\n");
      |                                  ^
main.c:34:18: error: request for member 'right' in something not a structure or union
   34 |     else if((A[i].right!=NIL&&A[i].left==NIL)||(A[i].right==NIL&&A[i].left!=NIL)||(A[i].right!=NIL&&A[i].left!=NIL))printf("internal node\n");
      |                  ^
main.c:34:35: error: request for member 'left' in something not a structure or union
   34 |     else if((A[i].right!=NIL&&A[i].left==NIL)||(A[i].right==NIL&&A[i].left!=NIL)||(A[i].right!=NIL&&A[i].left!=NIL))printf("internal node\n");
      |                                   ^
main.c:34:53: error: request for member 'right' in something not a structure or union
   34 |     else if((A[i].right!=NIL&&A[i].left==NIL)||(A[i].right==NIL&&A[i].left!=NIL)||(A[i].right!=NIL&&A[i].left!=NIL))printf("internal node\n");
      |                                                     ^
main.c:34:70: error: request for member 'left' in something not a structure or union
   34 |     else if((A[i].right!=NIL&&A[i].left==NIL)||(A[i].right==NIL&&A[i].left!=NIL)||(A[i].right!=NIL&&A[i].left!=NIL))printf("internal node\n");
      |                                                                      ^
main.c:34:88: error: request for member 'right' in something not a structure or union
   34 |     else if((A[i].right!=NIL&&A[i].left==NIL)||(A[i].right==NIL&&A[i].left!=NIL)||(A[i].right!=NIL&&A[i].left!=NIL))printf("internal node\n");
      |                                                                                        ^
main.c:34:105: error: request for member 'left' in something not a structure or union
   34 |     else if((A[i].right!=NIL&&A[i].left==NIL)||(A[i].right==NIL&&A[i].left!=NIL)||(A[i].right!=NIL&&A[i].left!=NIL))printf("internal node\n");
      |                                                                                                         ^
main.c: At top level:
main.c:40:6: warning: conflicting types for 'preparse'; have 'void(int)'
   40 | void preparse(int u){
      |      ^~~~~~~~
main.c:26:5: note: previous implicit declaration of 'preparse' with type 'void(int)'
   26 |     preparse(root);
      |     ^~~~~~~~
main.c: In function 'preparse':
main.c:43:9: error: 'NIL' undeclared (first use in this function)
   43 |   if(u==NIL) return;
      |         ^~~
main.c:45:7: error: request for member 'depth' in something not a structure or union
   45 |   A[u].depth=count;
      |       ^
main.c:47:16: error: request for member 'left' in something not a structure or union
   47 |   preparse(A[u].left);
      |                ^
main.c:48:16: error: request for member 'right' in something not a structure or union
   48 |   preparse(A[u].right);
      |                ^
main.c: At top level:
main.c:52:6: warning: conflicting types for 'sibling'; have 'void(int,  int,  int)'
   52 | void sibling(int u,int r,int l){
      |      ^~~~~~~
main.c:27:3: note: previous implicit declaration of 'sibling' with type 'void(int,  int,  int)'
   27 |   sibling(root,A[root].right,A[root].left);
      |   ^~~~~~~
main.c: In function 'sibling':
main.c:55:9: error: 'NIL' undeclared (first use in this function)
   55 |   if(u==NIL) return;
      |         ^~~
main.c:56:10: error: request for member 'left' in something not a structure or union
   56 |   if(A[u].left!=NIL && A[u].right!=NIL) {
      |          ^
main.c:56:28: error: request for member 'right' in something not a structure or union
   56 |   if(A[u].left!=NIL && A[u].right!=NIL) {
      |                            ^
main.c:57:9: error: request for member 'sibling' in something not a structure or union
   57 |     A[l].sibling=A[u].right;
      |         ^
main.c:57:22: error: request for member 'right' in something not a structure or union
   57 |     A[l].sibling=A[u].right;
      |                      ^
main.c:58:9: error: request for member 'sibling' in something not a structure or union
   58 |     A[r].sibling=A[u].left;
      |         ^
main.c:58:22: error: request for member 'left' in something not a structure or union
   58 |     A[r].sibling=A[u].left;
      |                      ^
main.c:61:15: error: request for member 'left' in something not a structure or union
   61 |   sibling(A[u].left,A[l].right,A[l].left);
      |               ^
main.c:61:25: error: request for member 'right' in something not a structure or union
   61 |   sibling(A[u].left,A[l].right,A[l].left);
      |                         ^
main.c:61:36: error: request for member 'left' in something not a structure or union
   61 |   sibling(A[u].left,A[l].right,A[l].left);
      |                                    ^
main.c:62:15: error: request for member 'right' in something not a structure or union
   62 |   sibling(A[u].right,A[r].right,A[r].left);
      |               ^
main.c