RosettaCodeData/Task/AVL-tree/Tcl/avl-tree-2.tcl
2023-07-01 13:44:08 -04:00

20 lines
445 B
Tcl

# Create an AVL tree
AVL::Tree create tree
# Populate it with some semi-random data
for {set i 33} {$i < 127} {incr i} {
[tree insert $i] setValue \
[string repeat [format %c $i] [expr {1+int(rand()*5)}]]
}
# Print it out
tree print
# Look up a few values in the tree
for {set i 0} {$i < 10} {incr i} {
set k [expr {33+int((127-33)*rand())}]
puts $k=>[[tree lookup $k] value]
}
# Destroy the tree and all its nodes
tree destroy