sorted container

Discussion in 'C++' started by Gary Wessle, Mar 7, 2007.

  1. Gary Wessle

    Gary Wessle Guest

    Hi
    I have some numbers of type double, as they come in, I need to keep
    track of the lowest and largest number. is there a self sorted
    container where I can insert the numbers in and just call front() and
    back() to get the largest and smallest numbers?

    thanks
     
    Gary Wessle, Mar 7, 2007
    #1
    1. Advertising

  2. Gary Wessle

    benben Guest

    Gary Wessle wrote:
    > Hi
    > I have some numbers of type double, as they come in, I need to keep
    > track of the lowest and largest number. is there a self sorted
    > container where I can insert the numbers in and just call front() and
    > back() to get the largest and smallest numbers?
    >
    > thanks


    Doesn't std::map do just that?

    Ben
     
    benben, Mar 7, 2007
    #2
    1. Advertising

  3. Gary Wessle

    Rolf Magnus Guest

    benben wrote:

    > Gary Wessle wrote:
    >> Hi
    >> I have some numbers of type double, as they come in, I need to keep
    >> track of the lowest and largest number. is there a self sorted
    >> container where I can insert the numbers in and just call front() and
    >> back() to get the largest and smallest numbers?
    >>
    >> thanks

    >
    > Doesn't std::map do just that?


    std::set seems more appropriate.
     
    Rolf Magnus, Mar 7, 2007
    #3
  4. Gary Wessle

    dasjotre Guest

    On 7 Mar, 11:03, Gary Wessle <> wrote:
    > Hi
    > I have some numbers of type double, as they come in, I need to keep
    > track of the lowest and largest number. is there a self sorted
    > container where I can insert the numbers in and just call front() and
    > back() to get the largest and smallest numbers?
    >
    > thanks


    std::multisert<double>
    it doesn't have front and back but you can use begin and rbegin
     
    dasjotre, Mar 7, 2007
    #4
  5. Gary Wessle

    Lionel B Guest

    On Wed, 07 Mar 2007 22:03:30 +1100, Gary Wessle wrote:

    > Hi
    > I have some numbers of type double, as they come in, I need to keep
    > track of the lowest and largest number. is there a self sorted
    > container where I can insert the numbers in and just call front() and
    > back() to get the largest and smallest numbers?


    std::set

    --
    Lionel B
     
    Lionel B, Mar 7, 2007
    #5
  6. Gary Wessle

    Kai-Uwe Bux Guest

    Gary Wessle wrote:

    > Hi
    > I have some numbers of type double, as they come in, I need to keep
    > track of the lowest and largest number. is there a self sorted
    > container where I can insert the numbers in and just call front() and
    > back() to get the largest and smallest numbers?


    Others have alerted you to std::map and std::set already. I would like to
    add that these containers will _not_ insert multiple copies of the same
    value. If you need to allow for repetitions of values, you should consider
    std::multiset.


    Best

    Kai-Uwe Bux
     
    Kai-Uwe Bux, Mar 7, 2007
    #6
  7. Gary Wessle

    benben Guest

    Rolf Magnus wrote:
    > benben wrote:
    >
    >> Gary Wessle wrote:
    >>> Hi
    >>> I have some numbers of type double, as they come in, I need to keep
    >>> track of the lowest and largest number. is there a self sorted
    >>> container where I can insert the numbers in and just call front() and
    >>> back() to get the largest and smallest numbers?
    >>>
    >>> thanks

    >> Doesn't std::map do just that?

    >
    > std::set seems more appropriate.
    >
    >


    Aha, think so! Had a tiring day my head wasn't functioning all right I
    guess :) Yes std::map needs key-value pair; so std::multiset really
    seems to be the most appropriate solution.

    Thanks for pointing out Rolf!

    Cheers,
    Ben
     
    benben, Mar 7, 2007
    #7
  8. Gary Wessle

    Guest

    On Mar 7, 6:03 am, Gary Wessle <> wrote:
    > Hi
    > I have some numbers of type double, as they come in, I need to keep
    > track of the lowest and largest number. is there a self sorted
    > container where I can insert the numbers in and just call front() and
    > back() to get the largest and smallest numbers?
    >
    > thanks

    If you only need to keep track of the smallest and largest then
    just use two doubles (initialized correctly) and use two if
    statements. As the numbers come in, set the min and max
    appropriately.

    Using a container is not correct. It uses space for n doubles when
    clearly only 2 are needed.
     
    , Mar 7, 2007
    #8
    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. Vivi Orunitia
    Replies:
    11
    Views:
    4,488
    Martijn Lievaart
    Feb 4, 2004
  2. Maitre Bart
    Replies:
    2
    Views:
    528
    Maitre Bart
    Feb 11, 2004
  3. Steven T. Hatton
    Replies:
    4
    Views:
    3,916
    Rob Williscroft
    Dec 5, 2004
  4. Replies:
    4
    Views:
    806
    Daniel T.
    Feb 16, 2006
  5. Hunk
    Replies:
    18
    Views:
    752
Loading...

Share This Page