Join Date: May 2006, Posts: 10 Reputation: HAOBBOY is an unknown quantity at this point (<10) Stop

Discussion in 'C++' started by HAOBBoy@gmail.com, May 16, 2006.

  1. Guest

    Hello

    I am using a MAP as an associative array. The map automatically sorts
    by key. How can I stop this feature. I will may value as FIFO. I mean
    if I have the keys

    Key=value

    SSN=000-00-0000
    Name=JAA
    Age=66

    When I iterate through the map I don't want may data to print as

    Age
    NAME
    SSN

    I want it to be as is:
    SSN
    NAME
    AGE
    , May 16, 2006
    #1
    1. Advertising

  2. Mark P Guest

    Re: Join Date: May 2006, Posts: 10 Reputation: HAOBBOY is an unknownquantity at this point (<10) Stopping Sorting Feature of Maps

    wrote:
    > Hello
    >
    > I am using a MAP as an associative array. The map automatically sorts
    > by key. How can I stop this feature. I will may value as FIFO.


    You can't. That's what a map does. If you don't want this feature, use
    something that isn't sorted. std:vector and std::list would each work
    find for your apparent purposes. You'll need to make your own datatype
    to hold the key-value pairings.

    Mark


    > I mean
    > if I have the keys
    >
    > Key=value
    >
    > SSN=000-00-0000
    > Name=JAA
    > Age=66
    >
    > When I iterate through the map I don't want may data to print as
    >
    > Age
    > NAME
    > SSN
    >
    > I want it to be as is:
    > SSN
    > NAME
    > AGE
    >
    Mark P, May 16, 2006
    #2
    1. Advertising

  3. Earl Purple Guest

    Re: Join Date: May 2006, Posts: 10 Reputation: HAOBBOY is an unknown quantity at this point (<10) Stopping Sorting Feature of Maps

    Mark P wrote:
    > wrote:


    > > Hello
    > >
    > > I am using a MAP as an associative array. The map automatically sorts
    > > by key. How can I stop this feature. I will may value as FIFO.

    >
    > You can't. That's what a map does. If you don't want this feature, use
    > something that isn't sorted. std:vector and std::list would each work
    > find for your apparent purposes. You'll need to make your own datatype
    > to hold the key-value pairings.
    >
    > Mark


    To maintain order and also have a fast lookup, you need to create an
    index and there is a boost library that will do that, although if you
    just want one index, it's easy enough to implement your own.

    Just have the vector in the regular order, and a map from keys to the
    addresses of elements in the vector (safe as long as the vector is
    built once then subsequently only referenced). Alternatively you can
    have map from key to the position (index) within the vector. (map<K,
    std::vector<T>::size_type > where T is your type and K is your key
    type).
    Earl Purple, May 17, 2006
    #3
  4. Earl Purple Guest

    Re: Join Date: May 2006, Posts: 10 Reputation: HAOBBOY is an unknown quantity at this point (<10) Stopping Sorting Feature of Maps

    wrote:
    > Hello
    >

    You seem to have copied and pasted the title of this post from
    codeguru.
    Earl Purple, May 17, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Saraswati lakki
    Replies:
    0
    Views:
    1,321
    Saraswati lakki
    Jan 6, 2012
  2. Mike
    Replies:
    1
    Views:
    521
  3. Replies:
    1
    Views:
    210
    John B. Matthews
    Jul 24, 2012
  4. Surya Kasturi

    how to calculate reputation

    Surya Kasturi, Jul 2, 2013, in forum: Python
    Replies:
    5
    Views:
    103
    Steven D'Aprano
    Jul 3, 2013
  5. Ian Kelly

    Re: how to calculate reputation

    Ian Kelly, Jul 2, 2013, in forum: Python
    Replies:
    0
    Views:
    89
    Ian Kelly
    Jul 2, 2013
Loading...

Share This Page