Hi want to implement an unordered hashmap ie. FIFO implementation using the standard hash_map library . Below is the sample i tested.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";
}
}
The output i get is
It gives output as
1
2
5
But I want . ie i want it in the same way i inserted it .
1
5
2
Any suggestions ?
|
Contributor
|
|
| 14Jan2009,00:05 | #2 |
|
If you want to display in the same way you inserted, you have to display in the sameway.. 1st, then 3rd and then 2nd values.. not using a for loop by incrementing iterator..
|
|
Newbie Member
|
|
| 28Jan2009,12:58 | #3 |
|
After lots of trial and error i have found the answer .
In hashmap the hashFunc 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 ) ... ![]() ![]()
|

