1. ## balance binary tree

I found this code on the net, but it doesn't work.
Can someone provide me with some guidance.
i created an accending sorted array, then executed the following code. Is this the most efficient way to do this? Is this a valid way to do this?

Code:
```// Assuming array ranges from [0..arraySize-1]
GetFromOrderedArray(0,arraySize-1)
.
.
void GetFromOrderedArray(int lowBound,int highBound)
{
if (highBound < lowBound) return;
middlePos = lowBound+(highBound-lowBound)/2
// middlePos is now at the element in the middle
// between lowBound and highBound, so we just add
// it to the tree

// Pick the middle one "to the left"

// Pick the middle one "to the right"
}```
Above code found from this link

I inserted test data to trace (no compiler available).
An array

- 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - <-index
--------------------------------
|1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |9 | <-Data
--------------------------------

In my trace it inserts 5,2,1,7,8,9 in that order.
On my compile earlier at home it only inserted 2.

more trace details

recursive calls |Hi|Low| middlePos <-column labels
start|8|0|4|
rc1|3|0|1
rc2|1|0|0
nrc1|8|5|6
nrc2|8|7|7
nrc3|8|8|8
nrc4|8|9|

3. ## i figured it out.

It took me a while to fix it, but I did.
Do not reinvent the wheel.
and also
reuse, reuse, reuse.
isn't code made for people to interpret and alter to fit their needs.

4. Generally, code made for people to reuse works.

5. Besides, std::set or std::map are already implemented as self-balancing binary trees, so use them. They aren't perfectly balanced, of course, but a worst-case node is at most twice as far from the root as a best-case.

There is less ability to do various traversal types, but it's much faster.

It's also faster on large sets, because your algorithm requires presorting the data -- self-balanced trees don't require a presort.

6. Besides, std::set or std::map are already implemented as self-balancing binary trees, so use them. They aren't perfectly balanced, of course, but a worst-case node is at most twice as far from the root as a best-case.
Is there a website you recommend that references the set and map?
I've never heard of that before.
I will search google, but if you have any good indepth references I would very much appreciate it.
Thanks.