include stdio include stdlib typedef struct node char name int visited

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
char* name;
int visited;
struct node* parents;
} node;
int count_skills(node *dest) {
int ret = 1;
dest->visited = 1;
if (!dest->parents) {
printf("%s no parents\n", dest->name);
return ret;
}
for(node*n = dest->parents; n; n++){
printf("next parent of %s: %s %x\n", dest->name, n->name, n);
if (n->visited){
continue;
}
ret += count_skills(n);
}
return ret;
}
int main(void) {
node magic = {"magic", 0, NULL};
node **p_parents = {&magic, NULL};
node projectiles = {"projectiles", 0, p_parents[0]};
node **f_parents = {&magic, NULL};
node fire = {"fire", 0, f_parents[0]};
node **fb_parents = {&projectiles, &fire, NULL};
node fireball = {"fireball", 0, fb_parents[0]};
printf("%d\n", count_skills(&fireball));
}