return r;
}
-int find_end(struct node *node, char **visited, int nvisited, bool twice)
+int find_end(struct node *node, char **visited, int nvisited, bool twice, char **path, int npath)
{
- if (strcmp(node->key, "end") == 0)
+ if (strcmp(node->key, "end") == 0) {
+ printf("path: ");
+ for (int i = 0; i<npath; i++)
+ printf("%s,", path[i]);
+ printf("\n");
return 1;
+ }
if (islower(node->key[0])) {
for (int i = 0; i<nvisited; i++)
if (strcmp(node->key, visited[i]) == 0)
visited = realloc(visited, sizeof(char *)*(nvisited+1));
visited[nvisited++] = node->key;
}
+ path = realloc(path, sizeof(char *)*(npath+1));
+ path[npath++] = node->key;
int r = 0;
for (struct conn *c = node->connections; c != NULL; c = c->hh.next) {
if (twice && strcmp(node->key, "start") != 0 && islower(node->key[0]))
- r += find_end(c->node, copy_visited(visited, nvisited-1), nvisited-1, false);
- r += find_end(c->node, copy_visited(visited, nvisited), nvisited, twice);
+ r += find_end(c->node, copy_visited(visited, nvisited-1), nvisited-1, false, copy_visited(path, npath), npath);
+ r += find_end(c->node, copy_visited(visited, nvisited), nvisited, twice, copy_visited(path, npath), npath);
}
free(visited);
return r;
get_or_create(&graph, toname));
}
- printf("%d\n", find_end(get_or_create(&graph, "start"), NULL, 0, true));
+ find_end(get_or_create(&graph, "start"), NULL, 0, true, NULL, 0);
+// printf("%d\n", find_end(get_or_create(&graph, "start"), NULL, 0, true, NULL, 0));
}