home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 12 / CD_ASCQ_12_0294.iso / maj / 666 / topsort.prx < prev   
Text File  |  1991-10-04  |  400b  |  12 lines

  1. // transforms a partial order into a total order
  2. // topsort: map(string,string) x set(string) -> seq(string)
  3.  
  4. topsort(g,nodes;x,n) { x={x:x<-nodes;x notin rng g};
  5.           if(x=={}) return [];
  6.           else n=oneof x;
  7.           return [n] conc topsort(g ds {n}, nodes diff {n});};
  8. nodes = {"c1","c2","c3","c4","c5"};
  9. g     = {"c1" -> "c3", "c2" -> "c3", "c2" -> "c4", "c3" -> "c5",
  10.       "c4" -> "c5"};
  11. end
  12.