A tree-visualizer for Racket programming language
- Copy the file
tree-visualizer.rktinto the directory that contains your Racket files - Paste the following line at the top of your code:
(require "tree-visualizer.rkt")(visualize tree-type tree)Prints a tree nicely in the interactive window.
tree-typeSym - one of the following:'binary-tree- binary trees in the form of(make-node key left right)'cons-tree- trees in the form of(cons key (listof children))'list-tree- trees in the form of(list key (listof children))'struct-tree- trees in the form of(make-node key (listof children))
tree(anyof binary-tree cons-tree list-tree struct-tree) - a tree in one of the aforementioned forms
(define example-bt
(make-node 5
(make-node 3
(make-node 1 empty empty)
(make-node 4 empty empty))
(make-node 8
(make-node 7 empty empty)
(make-node 9 empty empty))))
(visualize 'binary-tree example-bt)handler-hashA hash that converts the tree-type (Sym) to its corresponding handler.
(binary->layout tree)
;; binary-tree -> tree-layoutConverts a binary-tree to a tree-layout for printing.
tree- a binary tree in the form of(make-node key left right)
(cons->generic tree)
;; cons-tree -> cons-treeConverts a cons-tree to a generic tree.
tree- a tree in the form of(cons key (listof children))
(list->generic tree)
;; list-tree -> cons-treeConverts a list-tree to a generic tree.
tree- a tree in the form of(list key (listof children))
(struct->generic tree)
;; struct-tree -> cons-treeConverts a struct-tree to a generic tree.
tree- a tree in the form of(make-node key (listof children))
(tree->tree-layout tree)
;; cons-tree -> tree-layoutConverts a generic tree to a tree-layout for printing.
tree- a tree in the form of(cons key (listof children))

