Hi,

My teacher asked us for homework to do the following task:

Create a binary tree with the vowels and walk through this tree using a pre-order traversal algorithm and insert the output in a array, then write an algorithm to print the array using post-order traversal.

I haven't figured out how can I do this, I can't use a tree, The traversal must be done using the array.

Does anyone have any idea?

For example using Wikipedia's traversal result (F, B, A, D, C, E, G, I, H), the execution logic might go like this:

``````F, B, A, D, C, E, G, I, H
^
F, B, A, D, C, E, G, I, H
^  ^
F, B, A, D, C, E, G, I, H
^     ^
F, B, A, D, C, E, G, I, H        A
^  ^  *
F, B, A, D, C, E, G, I, H        A
^     *  ^
F, B, A, D, C, E, G, I, H        A
^     *     ^
F, B, A, D, C, E, G, I, H        A, C
^     *  ^  *
F, B, A, D, C, E, G, I, H        A, C
^     *     *  ^
F, B, A, D, C, E, G, I, H        A, C, E
^     *  ^  *  *
F, B, A, D, C, E, G, I, H        A, C, E, D
^  ^  *  *  *  *
F, B, A, D, C, E, G, I, H        A, C, E, D, B
^  *  *  *  *  *
F, B, A, D, C, E, G, I, H        A, C, E, D, B
^  *  *  *  *  *  ^
F, B, A, D, C, E, G, I, H        A, C, E, D, B
^  *  *  *  *  *     ^
F, B, A, D, C, E, G, I, H        A, C, E, D, B
^  *  *  *  *  *        ^
F, B, A, D, C, E, G, I, H        A, C, E, D, B, H
^  *  *  *  *  *     ^  *
F, B, A, D, C, E, G, I, H        A, C, E, D, B, H, I
^  *  *  *  *  *  ^  *  *
F, B, A, D, C, E, G, I, H        A, C, E, D, B, H, I, G
^  *  *  *  *  *  *  *  *
F, B, A, D, C, E, G, I, H        A, C, E, D, B, H, I, G, F
*  *  *  *  *  *  *  *  *
``````

The idea is that at each step you'd select a root, then find the smallest unprocessed item first from the left "subtree" (anything less than the root), then from the right subtree (anything greater than or equal to the root). The steps would be done recursively, so subtrees themselves could also have left and right subtrees.