Language: C

#include<stdio.h>
#define N 100000

typdef struct{
int parent,left,right;
}

int depth;
int height;

Node node[N];

int main(){
int i,j,n,id,child;

scanf("%d",&n);
for(i=0;i<n;i++){
node[i].parent=node[i].left=node[i].right=-1;
}
for(i = 0;i < n;i++){
scanf("%d", &id);
for(j = 0;j < 2;j++){
scanf("%d", &child);
if(child != -1){
node[child].parent = id;
if(j == 0){
node[id].left = child;
}
else{
node[id].right = child;
}
}
}
}

for(i = 0;i < n;i++){
printf("node %d: parent = %d, sibling = ", i, node[i].parent);
if(node[i].parent == -1){
printf("-1, ");
}
else{
if(node[node[i].parent].right == -1){
if(node[node[i].parent].left != -1 && node[node[i].parent].left != i){
printf("%d, ", node[node[i].parent].left);
}
else{
printf("-1, ");
}
}
else{
if(node[node[i].parent].right != i){
printf("%d, ", node[node[i].parent].right);
}
else{
printf("%d, ", node[node[i].parent].left);
}
}
}

printf("degree = ");
if(node[i].left == -1){
if(node[i].right == -1){
printf("0, ");
}
else{
printf("1, ");
}
}
else{
if(node[i].right == -1){
printf("1, ");
}
else{
printf("2, ");
}
}

printf("depth = %d, height = %d, ", depth(i), height(i));

if(node[i].parent == -1){
printf("root\n");
}
else{
if(node[i].left == -1){
if(node[i].right != -1){
printf("internal node\n");
}
else{
printf("leaf\n");
}
}
else{
printf("internal node\n");
}
}
}
return 0;
}

int depth(int id){
int dep = 0;
while(1){
if(node[id].parent == -1){
return dep;
}
else{
dep++;
id = node[id].parent;
}
}
}

int height(int id){
int hei, l = 0, r = 0;
if(node[id].left == -1){
if(node[id].right == -1){
return 0;
}
else{
r += height(node[id].right) + 1;
}
}
else{
l += height(node[id].left) + 1;
if(node[id].right != -1){
r += height(node[id].right) + 1;
}
}
if(l < r){
return r;
}
else{
return l;
}
}
}
return 0;



Compiler output:
main.c:4:7: error: expected ';' before 'struct'
    4 | typdef struct{
      |       ^~~~~~~
      |       ;
main.c:8:1: error: expected ';', identifier or '(' before 'int'
    8 | int depth;
      | ^~~
main.c:11:1: error: unknown type name 'Node'
   11 | Node node[N];
      | ^~~~
main.c: In function 'main':
main.c:18:8: error: request for member 'parent' in something not a structure or union
   18 | node[i].parent=node[i].left=node[i].right=-1;
      |        ^
main.c:18:23: error: request for member 'left' in something not a structure or union
   18 | node[i].parent=node[i].left=node[i].right=-1;
      |                       ^
main.c:18:36: error: request for member 'right' in something not a structure or union
   18 | node[i].parent=node[i].left=node[i].right=-1;
      |                                    ^
main.c:25:12: error: request for member 'parent' in something not a structure or union
   25 | node[child].parent = id;
      |            ^
main.c:27:9: error: request for member 'left' in something not a structure or union
   27 | node[id].left = child;
      |         ^
main.c:30:9: error: request for member 'right' in something not a structure or union
   30 | node[id].right = child;
      |         ^
main.c:37:54: error: request for member 'parent' in something not a structure or union
   37 | printf("node %d: parent = %d, sibling = ", i, node[i].parent);
      |                                                      ^
main.c:38:11: error: request for member 'parent' in something not a structure or union
   38 | if(node[i].parent == -1){
      |           ^
main.c:42:16: error: request for member 'parent' in something not a structure or union
   42 | if(node[node[i].parent].right == -1){
      |                ^
main.c:43:16: error: request for member 'parent' in something not a structure or union
   43 | if(node[node[i].parent].left != -1 && node[node[i].parent].left != i){
      |                ^
main.c:43:51: error: request for member 'parent' in something not a structure or union
   43 | if(node[node[i].parent].left != -1 && node[node[i].parent].left != i){
      |                                                   ^
main.c:44:28: error: request for member 'parent' in something not a structure or union
   44 | printf("%d, ", node[node[i].parent].left);
      |                            ^
main.c:51:16: error: request for member 'parent' in something not a structure or union
   51 | if(node[node[i].parent].right != i){
      |                ^
main.c:52:28: error: request for member 'parent' in something not a structure or union
   52 | printf("%d, ", node[node[i].parent].right);
      |                            ^
main.c:55:28: error: request for member 'parent' in something not a structure or union
   55 | printf("%d, ", node[node[i].parent].left);
      |                            ^
main.c:61:11: error: request for member 'left' in something not a structure or union
   61 | if(node[i].left == -1){
      |           ^
main.c:62:11: error: request for member 'right' in something not a structure or union
   62 | if(node[i].right == -1){
      |           ^
main.c:70:11: error: request for member 'right' in something not a structure or union
   70 | if(node[i].right == -1){
      |           ^
main.c:78:37: error: called object 'depth' is not a function or function pointer
   78 | printf("depth = %d, height = %d, ", depth(i), height(i));
      |                                     ^~~~~
main.c:8:5: note: declared here
    8 | int depth;
      |     ^~~~~
main.c:78:47: error: called object 'height' is not a function or function pointer
   78 | printf("depth = %d, height = %d, ", depth(i), height(i));
      |                                               ^~~~~~
main.c:9:5: note: declared here
    9 | int height;
      |     ^~~~~~
main.c:80:11: error: request for member 'parent' in something not a structure or union
   80 | if(node[i].parent == -1){
      |           ^
main.c:84:11: error: request for member 'left' in something not a structure or union
   84 | if(node[i].left == -1){
      |           ^
main.c:85:11: error: request for member 'right' in something not a structure or union
   85 | if(node[i].right != -1){
      |           ^
main.c: At top level:
main.c:100:5: error: 'depth' redeclared as different kind of symbol
  100 | int depth(int id){
      |     ^~~~~
main.c:8:5: note: previous declaration of 'depth' with type 'int'
    8 | int depth;
      |     ^~~~~
main.c: In function 'depth':
main.c:103:12: error: request for member 'parent' in something not a structure or union
  103 | if(node[id].parent == -1){
      |            ^
main.c:108:14: error: request for member 'parent' in something not a structure or union
  108 | id = node[id].parent;
      |              ^
main.c: At top level:
main.c:113:5: error: 'height' redeclared as different kind of symbol
  113 | int height(int id){
      |     ^~~~~~
main.c:9:5: note: previous declaration of 'height' with type 'int'
    9 | int height;
      |     ^~~~~~
main.c: In function 'height':
main.c:115:12: error: request for member 'left' in something not a structure or union
  115 | if(node[id].left == -1){
      |            ^
main.c:116:12: error: request for member 'right' in something not a structure or union
  116 | if(node[id].right == -1){
      |            ^
main.c:120:21: error: request for member 'right' in something not a structure or union
  120 | r += height(node[id].right) + 1;
      |                     ^
main.c:124:21: error: request for member 'left' in something not a structure or union
  124 | l += height(node[id].left) + 1;
      |                     ^
main.c:125:12: error: request for member 'right' in something not a structure or union
  125 | if(node[id].right != -1){
      |            ^
main.c:126:21: error: request for member 'right' in something not a structure or union
  126 | r += height(node[id].right) + 1;
      |                     ^
main.c: At top level:
main.c:136:1: error: expected identifier or '(' before '}' token
  136 | }
      | ^
main.c:137:1: error: expected identifier or '(' before 'return'
  137 | return 0;
      | ^~~~~~