Language: C

#include <stdio.h>
#include <stdlib.h>

#define MAX 10000

typedef struct {
  int node=0;
  int i; //挿入された順番
  int parent; //初期値-1,ノード0対策 
  int depth; //depth = parent->depth + 1
  int k; //childの数
  int *child;
} Tree;

struct Node {
  int key;
  Tree item;
  struct Node *next;
  struct Node *prev;
};

typedef struct Node *NodePointer;

/*外部変数*/
NodePointer head;

NodePointer make_1node(int , NodePointer );
NodePointer finditem(int );
NodePointer insert(int ,NodePointer ); //普通のリスト作成
NodePointer findnode(int);
/*使わなくてもなんとかなった...*/
NodePointer insert2(int,NodePointer ); //挿入タイプのリスト作成

int main() {
  int n;
  int id,k=0;
  int i,j;
  int judge_parent=0;
  int judge_insert=0;
  NodePointer node;
  NodePointer node_tmp;
  
  head = make_1node(0,NULL);
  node = head;
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    /*ノードを小さい方から出力するためにnodeを引数に使う(ハンドアウトはheadの次に入れる)*/
    /*
    insert(i,node);
    node=node->next;
    */
    scanf("%d",&id);
    
    for(node=head;node->next!=NULL;node=node->next) {
      //fprintf(stderr,"check");
      if((node->next)->item.node > id) {
        insert(i,node);
	node=node->next;
        //node->item.i = i;
        judge_insert=1;
        break;
      }
    }
    //printf("check");

    if(judge_insert == 0) {
      insert(i,node);
      node=node->next;
      node->item.i = i;
    }
    judge_insert = 0;
    node->item.node = id;
    scanf(" %d",&k);
    node->item.k = k;
    node->item.child = (int *)malloc(k * sizeof(int));
    for(j=0;j<k;j++) {
      scanf(" %d",&(node->item.child[j]));
    }
    node->item.parent = -1;//初期値-1,ノード0対策
    node->item.depth = 0;
  }
    /*ここまでで入力完了*/
    /*親検索、childを端から調べる(なんだこれ)*/
  for(node=head->next;node!=NULL;node=node->next) {
    for(node_tmp=head->next;node_tmp!=NULL;node_tmp=node_tmp->next) {
      //printf("node:%d || node_tmp:%d Child,",node->item.node,node_tmp->item.node);
      for(j=0;j<node_tmp->item.k;j++) {
        //printf("%d ,",node_tmp->item.child[j]);
        if(node_tmp->item.child[j] == node->item.node) {
          node->item.parent = node_tmp->item.node;
	  node->item.depth = node_tmp->item.depth + 1;
          //printf("check");
          judge_parent = 1;
          break;
        }
      }
      //printf("\n");
      if(judge_parent==1) break;
    }
    judge_parent=0; //初期化
  }
    /*深さ決定*/
  /*
  for(node=head->next;node!=NULL;node=node->next) {
    if(node->item.parent == -1) node->item.depth = 0;
    else {
      node_tmp = findnode(node->item.parent); //親を検索、node_tmpを親にする
      //printf("node_tmp:%d \n",node_tmp->item.node);
      node->item.depth = (node_tmp->item.depth) + 1; //深さは親の深さに+1したもの
    }
  }
  */

  /*後から親が判明→depthでエラー
    先に親が判明→routが二つになる*/

  for(node=head->next;node!=NULL;node=node->next) {
    //printf("node:%d || depth:%d \n",node->item.node,node->item.depth);
    printf("node %d: parent = %d, depth = %d, ",node->item.node,node->item.parent,node->item.depth);
    /*root,internal node,leafの判定、root=親無し、k>0=子持ち*/
    if(node->item.parent == -1) printf("root, ");
    else if(node->item.k > 0) printf("internal node, ");
    else printf("leaf, ");
    printf("[");
    if(node->item.k > 0) {
      for(j=0;j<(node->item.k)-1;j++) printf("%d, ",node->item.child[j]);
      printf("%d",node->item.child[j]);
    }
    printf("]\n");
  }

  return 0;
}

//ノードの作成
NodePointer make_1node(int keydata, NodePointer p) {
	NodePointer n;

	if ((n = (NodePointer)malloc(sizeof(struct Node))) == NULL) {
		exit(1);
	}
	n->key = keydata;
	n->next = p;
	n->prev = p;

}

//ノードの検索
NodePointer finditem(int value) {
	NodePointer n;

	for (n = head; n->next != NULL; n = n->next) {
		if (n->next->key == value) return n;
	}
	return NULL;
}

//depthを調べるために親を求める関数、
NodePointer findnode(int nodekey) {
        NodePointer n;

        for (n = head->next; n != NULL; n = n->next) {
                if (n->item.node == nodekey) return n;
        }
        return NULL;
}


//ノードの挿入
NodePointer insert(int keydata,NodePointer node) {
	NodePointer newnode;

	if (finditem(keydata) == NULL) {
		newnode = make_1node(keydata, node->next);
		newnode->next = node->next;
		if(newnode->next != NULL) (newnode->next)->prev = newnode;
		node->next = newnode;
		//newnode->next = node;
		newnode->prev = node;

		return newnode;
	}
	else {
		return NULL;
	}
}

NodePointer insert2(int keydata,NodePointer node) {
        NodePointer newnode;

        if (finditem(keydata) == NULL) {
                newnode = make_1node(keydata, node->next);
                newnode->next = node->next;
                if(newnode->next != NULL) (newnode->next)->prev = newnode;
                node->next = newnode;
                newnode->next = node;
                //newnode->prev = node;

                return newnode;
        }
        else {
                return NULL;
        }
}



Compiler output:
main.c:7:11: error: expected ':', ',', ';', '}' or '__attribute__' before '=' token
    7 |   int node=0;
      |           ^
main.c: In function 'main':
main.c:56:28: error: 'Tree' has no member named 'node'
   56 |       if((node->next)->item.node > id) {
      |                            ^
main.c:69:17: error: 'Tree' has no member named 'i'
   69 |       node->item.i = i;
      |                 ^
main.c:72:15: error: 'Tree' has no member named 'node'
   72 |     node->item.node = id;
      |               ^
main.c:74:15: error: 'Tree' has no member named 'k'
   74 |     node->item.k = k;
      |               ^
main.c:75:15: error: 'Tree' has no member named 'child'
   75 |     node->item.child = (int *)malloc(k * sizeof(int));
      |               ^
main.c:77:31: error: 'Tree' has no member named 'child'
   77 |       scanf(" %d",&(node->item.child[j]));
      |                               ^
main.c:79:15: error: 'Tree' has no member named 'parent'
   79 |     node->item.parent = -1;//初期値-1,ノード0対策
      |               ^
main.c:80:15: error: 'Tree' has no member named 'depth'
   80 |     node->item.depth = 0;
      |               ^
main.c:87:31: error: 'Tree' has no member named 'k'
   87 |       for(j=0;j<node_tmp->item.k;j++) {
      |                               ^
main.c:89:26: error: 'Tree' has no member named 'child'
   89 |         if(node_tmp->item.child[j] == node->item.node) {
      |                          ^
main.c:89:49: error: 'Tree' has no member named 'node'
   89 |         if(node_tmp->item.child[j] == node->item.node) {
      |                                                 ^
main.c:90:21: error: 'Tree' has no member named 'parent'
   90 |           node->item.parent = node_tmp->item.node;
      |                     ^
main.c:90:45: error: 'Tree' has no member named 'node'
   90 |           node->item.parent = node_tmp->item.node;
      |                                             ^
main.c:91:21: error: 'Tree' has no member named 'depth'
   91 |           node->item.depth = node_tmp->item.depth + 1;
      |                     ^
main.c:91:44: error: 'Tree' has no member named 'depth'
   91 |           node->item.depth = node_tmp->item.depth + 1;
      |                                            ^
main.c:119:59: error: 'Tree' has no member named 'node'
  119 |     printf("node %d: parent = %d, depth = %d, ",node->item.node,node->item.parent,node->item.depth);
      |                                                           ^
main.c:119:75: error: 'Tree' has no member named 'parent'
  119 |     printf("node %d: parent = %d, depth = %d, ",node->item.node,node->item.parent,node->item.depth);
      |                                                                           ^
main.c:119:93: error: 'Tree' has no member named 'depth'
  119 |     printf("node %d: parent = %d, depth = %d, ",node->item.node,node->item.parent,node->item.depth);
      |                                                                                             ^
main.c:121:18: error: 'Tree' has no member named 'parent'
  121 |     if(node->item.parent == -1) printf("root, ");
      |                  ^
main.c:122:23: error: 'Tree' has no member named 'k'
  122 |     else if(node->item.k > 0) printf("internal node, ");
      |                       ^
main.c:125:18: error: 'Tree' has no member named 'k'
  125 |     if(node->item.k > 0) {
      |                  ^
main.c:126:28: error: 'Tree' has no member named 'k'
  126 |       for(j=0;j<(node->item.k)-1;j++) printf("%d, ",node->item.child[j]);
      |                            ^
main.c:126:63: error: 'Tree' has no member named 'child'
  126 |       for(j=0;j<(node->item.k)-1;j++) printf("%d, ",node->item.child[j]);
      |                                                               ^
main.c:127:29: error: 'Tree' has no member named 'child'
  127 |       printf("%d",node->item.child[j]);
      |                             ^
main.c: In function 'findnode':
main.c:163:28: error: 'Tree' has no member named 'node'
  163 |                 if (n->item.node == nodekey) return n;
      |                            ^