Implement Map in C++

  • Thread starter Thread starter Sean
  • Start date Start date
S

Sean

Hi all,

I wonder what are the possible ways to implement a Map
in C++?
Among these methods, which is the best one and why?

Thank you very much in advance.


Sean
 
sounds like a homework question....


Use the STL's map:

#include <map>

It's the best because it's
a) written for you
b) debugged
c) standard
d) interoperates with other stl features


cheerio.
 
Hi,

Thanks for your reply.
It's not a homework question actually... but it's a
question that my friend asked me and I couldn't answer :)

I'm curious.
And I want to know how we can implement a Map in C++
without using the STL library. :)

I appreciate any ideas :)



Sean
 
Sean said:
Hi,

Thanks for your reply.
It's not a homework question actually... but it's a
question that my friend asked me and I couldn't answer :)

I'm curious.
And I want to know how we can implement a Map in C++
without using the STL library. :)

1. Use a Red-Black Tree (this is what most STL implementations use for
std::map)
2. Use a hash table (most STL implementations supply some form of hash_map)
3. Use an AVL tree.
4. Use a B Tree, B+ Tree or B* Tree.
5. Use a sorted vector of std::pair (this is actually more efficient in some
cases)
....

-cd
 
Back
Top