Add tsort.

This commit is contained in:
Sergiu Ivanov 2021-10-31 21:10:50 +01:00
parent f7c6c89672
commit ed5fc4d3b8

View file

@ -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))))