1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Unordered(FIFO) hash_map implementation . Plz help

Discussion in 'C++' started by veer123, Jan 13, 2009.

  1. veer123

    veer123 New Member

    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 ?
     
  2. sharmila

    sharmila New Member

    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..
     
  3. veer123

    veer123 New Member

    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:
     

Share This Page