diff --git a/graph.rkt b/graph.rkt index a24beae..348ad9e 100644 --- a/graph.rkt +++ b/graph.rkt @@ -35,7 +35,7 @@ bfs bfs/generalized fewest-vertices-path dfs dfs/generalized - dag? + dag? tsort graphviz) @@ -173,6 +173,8 @@ #:return finish)) (define (dag? g) (g:dag? (gg g))) + (define (tsort g) + (g:tsort (gg g))) ;; 10 Graphviz (define (graphviz g #:output [output #f] #:colors [colors #f]) @@ -254,6 +256,7 @@ #:return (-> Graph Any Any)) Any)] [dag? (-> Graph Boolean)] + [tsort (-> Graph (Listof Any))] ;; 10 Graphviz [graphviz (->* (Graph) @@ -355,7 +358,9 @@ (check-equal? (dfs/generalized (directed-graph '((a b) (a c) (b d) (c d)))) (void)) (check-true (dag? (directed-graph '((a b) (b c))))) - (check-false (dag? (directed-graph '((a b) (b a)))))) + (check-false (dag? (directed-graph '((a b) (b a))))) + (check-equal? (tsort (directed-graph '((a b) (b c) (a d) (d b)))) + '(a d b c))) (test-case "10 Graphviz" (define g (directed-graph '((a b) (b c))))