Skip to content

A tree structure visualizer for racket programming language

Notifications You must be signed in to change notification settings

Yuhao-C/racket-tree-visualizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

racket-tree-visualizer

A tree-visualizer for Racket programming language

Visualization of a binary expression tree

Installation

  1. Copy the file tree-visualizer.rkt into the directory that contains your Racket files
  2. Paste the following line at the top of your code:
(require "tree-visualizer.rkt")

Usage

(visualize tree-type tree)

Prints a tree nicely in the interactive window.

  • tree-type Sym - 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

Example

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

Produces:
Visualization of the binary tree example-bt


Developer Documentation

handler-hash

A hash that converts the tree-type (Sym) to its corresponding handler.

(binary->layout tree)
;; binary-tree -> tree-layout

Converts 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-tree

Converts a cons-tree to a generic tree.

  • tree - a tree in the form of (cons key (listof children))

(list->generic tree)
;; list-tree -> cons-tree

Converts a list-tree to a generic tree.

  • tree - a tree in the form of (list key (listof children))

(struct->generic tree)
;; struct-tree -> cons-tree

Converts 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-layout

Converts a generic tree to a tree-layout for printing.

  • tree - a tree in the form of (cons key (listof children))

About

A tree structure visualizer for racket programming language

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages