Skip to content

Instantly share code, notes, and snippets.

@carld
Forked from hilverd/tsort.g
Created June 8, 2020 06:27
Show Gist options
  • Save carld/e7f48dc15b870a850dd701900d279848 to your computer and use it in GitHub Desktop.
Save carld/e7f48dc15b870a850dd701900d279848 to your computer and use it in GitHub Desktop.
Topological sort in Graphviz's gvpr
BEGIN {
int visited[node_t];
int visit(node_t n, edge_t e) {
if (visited[n] == 0) {
visited[n] = 1;
for (e = fstin(n); e; e = nxtin(e)) {
visit(e.tail, NULL);
}
printf("%s\n", n.name);
}
return 0;
}
}
N {
visit($, NULL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment