Created
May 14, 2011 11:24
-
-
Save stesh/972126 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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