Language: C

#include <stdio.h>
#define N 25
??
typedef struct{
??
????int parent;
????int left;
????int right;
??
}Node;
??
int n;
Node in[N];
??
void init();
int sibling(int);
int depth(int);
int type(int);
int degree(int);
int height(int);
????
int main(){
??
????int i, id;
??????
????init();
??
????scanf("%d", &n);
??
????for(i = 0; i < n; i++){
????????scanf("%d", &id);
????????scanf("%d %d", &in[id].left, &in[id].right);
??????????
????????if(in[id].left == -1 && in[id].right == -1) continue;
??
????????in[in[id].left].parent = id;
????????in[in[id].right].parent = id;
????}
??
????for(i = 0; i < n; i++){
????????printf("node %d: parent = %d, sibling = %d, ", i, in[i].parent, sibling(i));
????????printf("degree = %d, depth = %d, height = %d, ", degree(i), depth(i), height(i));
??
????????if(type(i) == 0){
????????????printf("root\n");
????????} else if(type(i) == 1){
????????????printf("leaf\n");
????????} else if(type(i) == 2){
????????????printf("internal node\n");
????????}
??
????}
????return 0;
}
????
int depth(int num){
??????int i;
????????
??????for(i = 0; in[num].parent != -1; i++){
??????????num = in[num].parent;
??????}
??
??????return i;
}
????
void init(){
????int i;
??????
????for(i = 0; i < N; i++){
????????in[i].parent = -1;
????????in[i].left = -1;
????????in[i].right = -1;
????}
??
}
??
??

????
??
int type(int num){
??
????if(in[num].parent == -1){
????????return 0;
????}
??????
????if(in[num].left == -1 && in[num].right == -1){
????????return 1;
????}
??
????return 2;
??
}

int height(int num){
????int i;
????int heightLeft = -1, heightRight = -1;
??
????if(in[num].left != -1){
????????heightLeft = height(in[num].left);
????}


????if(in[num].right != -1){
????????heightRight = height(in[num].right);
????}
??????
????heightLeft++;
????heightRight++;
??????
????if(heightLeft > heightRight){
????????return heightLeft;
????} else {
????????return heightRight;
????}
??????
}
??
??
int sibling(int num){
??
????if(in[num].parent == -1){
????????return -1;
????}
??
????if(in[in[num].parent].left == num){
????????return in[in[num].parent].right;
????} else {
????????return in[in[num].parent].left;
????}
??
}
??
??
int degree(int num){
??????
????if(in[num].left == -1 && in[num].right == -1){
????????return 0;
????}
??
????if(in[num].left == -1 || in[num].right == -1){
??????????return 1;
????}
??
??????return 2;
??
}
??
??

Compiler output:
main.c:3:1: error: expected identifier or '(' before '?' token
    3 | ??
      | ^
main.c:10:2: warning: data definition has no type or storage class
   10 | }Node;
      |  ^~~~
main.c:10:2: error: type defaults to 'int' in declaration of 'Node' [-Wimplicit-int]
main.c:11:1: error: expected identifier or '(' before '?' token
   11 | ??
      | ^
main.c:13:1: error: unknown type name 'Node'
   13 | Node in[N];
      | ^~~~
main.c:14:1: error: expected identifier or '(' before '?' token
   14 | ??
      | ^
main.c:21:1: error: expected identifier or '(' before '?' token
   21 | ????
      | ^
main.c:55:1: error: expected identifier or '(' before '?' token
   55 | ????
      | ^
main.c:65:1: error: expected identifier or '(' before '?' token
   65 | ????
      | ^
main.c:76:1: error: expected identifier or '(' before '?' token
   76 | ??
      | ^
main.c: In function 'height':
main.c:96:1: error: expected expression before '?' token
   96 | ????int i;
      | ^
main.c:97:1: error: expected expression before '?' token
   97 | ????int heightLeft = -1, heightRight = -1;
      | ^
main.c:98:1: error: expected expression before '?' token
   98 | ??
      | ^
main.c:109:1: error: expected expression before '?' token
  109 | ????heightRight++;
      | ^
main.c:109:5: error: 'heightRight' undeclared (first use in this function)
  109 | ????heightRight++;
      |     ^~~~~~~~~~~
main.c:109:5: note: each undeclared identifier is reported only once for each function it appears in
main.c:110:1: error: expected expression before '?' token
  110 | ??????
      | ^
main.c: At top level:
main.c:118:1: error: expected identifier or '(' before '?' token
  118 | ??
      | ^
main.c:133:1: error: expected identifier or '(' before '?' token
  133 | ??
      | ^
main.c:148:1: error: expected identifier or '(' before '?' token
  148 | ??
      | ^