Unordered(FIFO) hash_map implementation . Plz help

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

  1. veer123

    veer123 New Member

    Joined:
    Jan 13, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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

    Joined:
    Mar 24, 2006
    Messages:
    75
    Likes Received:
    1
    Trophy Points:
    0
    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

    Joined:
    Jan 13, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice