sorted container

G

Gary Wessle

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
 
B

benben

Gary said:
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
 
D

dasjotre

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
 
L

Lionel B

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
 
K

Kai-Uwe Bux

Gary said:
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
 
B

benben

Rolf said:
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
 
A

AnonMail2005

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top