On 2007-05-19 18:35, osmium wrote:
Quote:
"Defected" writes:
>
Quote:
>How i can create a Binary Search Tree with a class ?
>
The wordsmiths at C++ decided that right word for "tree" was "map". So get
out your handy-dandy copy of Josuttis and go from there. Page 194.
Not really, a map is a class that allows you to map a key to a value and
have some guarantees on how fast some operations can be performed, on
most implementations a red-black tree, which is not a binary search tree.
To the OP:
To create a binary search tree you should probably have two classes, one
for the nodes and one for the tree. The nodes will be quite simple, they
only have to contain a value and links to child-nodes (and perhaps one
for the parent). The other class contains information about the tree
(number of nodes and so on) and a link to the root-node. It also
contains methods to insert, find, delete and so on. How to perform those
operations on the tree should be in your book on algorithms and data-
structures (or google if you don't have a book).
If you get any problems with getting the code to work then come back
here and post your code and describe your problem. However before
posting read the relevant sections of the FAQ first:
http://www.parashift.com/c++-faq-lite/how-to-post.html
--
Erik Wikström