TreeTest.frink

Download or view TreeTest.frink in plain text format


use Tree.frink

/** This contains routines to test the Tree class in Tree.frink. */

/** Create a random tree and insert items into it in a manner that will
    be binary searchable in order. */

a = toArray[1 to 10].shuffle[]
println["Inserting items $a"]

tree = undef
for elem = a
   tree = Tree.insertBinary[tree, elem]

println["\ndump:\n"]
println[tree.dump[]]

watcher = new PrintTreeWatcher
println["\nInorder traverse:"]
tree.inorderTraverse[watcher]

println["\npreorder traverse:"]
tree.preorderTraverse[watcher]

println["\npostorder traverse:"]
tree.postorderTraverse[watcher]

println["\nbreadth-first traverse:"]
tree.breadthFirstTraverse[watcher]

println["\ndepth-first traverse:"]
tree.depthFirstTraverse[watcher]

f= tree.toDotFile[false]
w = new Writer["tree1.dot"]
w.print[f]
w.close[]



Download or view TreeTest.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 20217 days, 23 hours, 25 minutes ago.