home *** CD-ROM | disk | FTP | other *** search
- // transforms a partial order into a total order
- // topsort: map(string,string) x set(string) -> seq(string)
-
- topsort(g,nodes;x,n) { x={x:x<-nodes;x notin rng g};
- if(x=={}) return [];
- else n=oneof x;
- return [n] conc topsort(g ds {n}, nodes diff {n});};
- nodes = {"c1","c2","c3","c4","c5"};
- g = {"c1" -> "c3", "c2" -> "c3", "c2" -> "c4", "c3" -> "c5",
- "c4" -> "c5"};
- end