Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Unordered(FIFO) hash_map implementation . Plz help (http://www.go4expert.com/forums/unordered-fifo-hashmap-implementation-t15807/)

veer123 13Jan2009 09:50

Unordered(FIFO) hash_map implementation . Plz help
 
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 ?

sharmila 14Jan2009 00:05

Re: Unordered(FIFO) hash_map implementation . Plz help
 
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..

veer123 28Jan2009 12:58

Re: Unordered(FIFO) hash_map implementation . Plz help
 
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 ) ...
:happy::happy::happy:


All times are GMT +5.5. The time now is 03:52.