tags:

views:

90

answers:

3

Is there any good tree manipulation (template) libraries for C++ out there that can do basic things like binary tree.

Though it is not difficult to write a binary tree all from scratch, but I'm really surprised that it is not so easy to find one ready-for-use.

+3  A: 

Trees are subsets of graphs. There are plenty of graph libraries out there, such as Boost Graph Library. You will have to add your vertices as you want and then use any one of the many visitors to traverse your tree.

Alternatively, you could custom make one with standard containers (think of a root node as containing 2 children that have a value and may have 2 other children).

s1n
is there an example on how to utilize BGL to implement, for example, a binary tree. I'm having trouble using it because of its abstractness.
lyxera
I can't think of specific binary tree examples, but a binary tree is a directed graph. Here's an example of a directed graph search using DFS (depth first search): http://www.boost.org/doc/libs/1_41_0/libs/graph/example/dfs-example.cpp
s1n
A: 

ACE has an implementation of Red Black tree. It is fairly easy to use.

link text

Dan
+1  A: 

What do you need the tree for? There may already be something in the STL or Boost that satisfies your need. For example: the STL std::map<key,value> is usually implemented as a balanced binary tree.

There is also tree.hh which implements an STL-like n-way tree.

Ferruccio
Just because the STL map is implemented using a tree doesn't mean it provides a tree-like data structure.
jon hanson