Hi want to implement an unordered hashmap ie. FIFO implementation . Below is the code.Please help me with this.

#include <hash_map>
#include <iostream.h>
int main()
{
hash_map<int,int>testMap;
testMap[1]=1;
testMap[3]=5;
testMap[2]=2;
typedef hash_map<int,int>::iterator hashIter;
for(hashIter it=testMap.begin();it!=testMap.end();it++)
{
cout<<it->second<<"\n";
}
}

It gives output as

1
2
5

But I want

1
5
2

Any suggestions ?

Member Avatar for jencas

Maybe boost::unordered_map is what you need, but I never have used it, so I can't say if it meets your conditions.

I want to use the hash map in the standard library . Is there a way to do this using the Standard Library hash_map

Member Avatar for jencas

No, you can't change the internal behaviour of hash_map.

You could always write your own implementation....that way it would only use things avaliable to you in the STL

Chris

:)
After lots of trial and error i have found the answer .

In hashmap the hashFunc::operator() has to be empty . Something like this

struct hashFunc

{

int operator() (int i) const

{

}

};

This will not sort the data it will be in the manner u insert it….It will be in the stack order. ( What you enter last will be on top ) ...
:icon_cool:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.