binary search tree question

If i had a key-value pair, or STL map, how could I store these together in a binary search tree?

For example, if I have name="doug" and phone number=xxxxxxxxxx, but I wanted to store both of those together, in a bst.
Binary search tree is a structure like this one:
1
2
3
4
struct Tree{
   SomeObject o;
   Tree *left, *right;
};
with methods inserting and finding nodes. These methods are based on your ability to compare two objects. Anything can go instead of SomeObject if you can compare them. So write a
1
2
3
4
struct Record{
   std::string name;
   int phone;
};
(not necessary, but may be more clear) and overload operators <, > for that struct (same here).
Here you are

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <map>

using namespace std;
struct classcomp {
    bool operator() (char *const& lhs, char *const& rhs) const
    {
        int i = strcmp(lhs, rhs);
        if(i<0) return true;
        return false;
    }
};

typedef map<char*, char*, classcomp> tyTelDir;
int main()
{
    tyTelDir TelDir;
    TelDir["SRK"] = "9988776655";
    TelDir["KRK"] = "8988776655";

    tyTelDir::iterator it;
    it = TelDir.find("SRK");

    if(it != TelDir.end())
    {
        cout << "Name:- " << it->first << " Tel No.: " << it->second;
    }

    it = TelDir.find("1doug");

    if(it != TelDir.end())
    {
        cout << "Name:- " << it->first << " Tel No.: " << it->second;
    }

    return 0;
}



See this link for more information
http://www.cplusplus.com/reference/stl/map/map/
Topic archived. No new replies allowed.