Advertisement

Binary Trees

Started by February 28, 2001 03:20 PM
0 comments, last by Zumichu 23 years, 11 months ago
I was just wondering if there are any good Binary Tree libraries around. These are use to hold the object of just about every game right? Does the stl have a good class for one? Something like that...or do I have to make my own? thanks.
[I did absolutely nothing, and it was everything that I thought it could be]
I'm almost positive that STL's std::map and std::set are what you want. They're implemented as red-black trees, which is a kind of self-balancing tree. map and set are nearly identical, except that map keeps its key seperate, whereas in a set, the value is the key.

Example, if you made a set of ints, and you inserted 20 random numbers, they would be sorted internally and you could search in logN time. The trick is that you can't make a set of user types unless you define a predicate for the type. Even then, you have to construct an object of that type every time you want to do a "find" on the set (which is the function I use most, other than insert and remove).

On the other hand, putting user types into a map is easy; you just have to make a good key. I use maps most of the time.

Look into set & map and I'm sure you'll get what you want. Repost or reply if you run into trouble; I'll be glad to help.

Edited by - Stoffel on February 28, 2001 7:53:26 PM

This topic is closed to new replies.

Advertisement