Skip to content

Instantly share code, notes, and snippets.

@stesh
Created May 14, 2011 11:24
Show Gist options
  • Save stesh/972126 to your computer and use it in GitHub Desktop.
Save stesh/972126 to your computer and use it in GitHub Desktop.
bst2array(tree : BST[G]; a : ARRAY[G]) is
require
tree /= Void
do
-- Traverse the tree in-order
if tree.left /= Void then
-- Recursively add all the elements of the left subtree
bst2array(tree.left, a)
end
-- Add the current element
a.add_last(tree.value)
if tree.right /= Void then
-- Recursively add all the elements of the right subtree
bst2array(tree.right, a)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment