peter55555
peter55555

Reputation: 1475

Associative container with finding element with the lowest value

I'm looking for a best solution. I'd like to store objects: key-value in container. I need a "good" access to every element by key and I need to find element with the lowest value.

What container would you recommend? Is there any better solution (in STL or Boost) than std::map? (Access to element is ok but looking for the lowest value is O(n) I guess)..

[Edited]

Sorry, I missed to add one very important thing. I actually want to get the lowest element (with the lowest value) and remove it...

Let's say my usage is:

1) access to some element (by key)

2) access to element with the lowest value and remove it

3) go to 1st step if container is not empty

What should I use? What do you think?

Upvotes: 0

Views: 102

Answers (1)

TNA
TNA

Reputation: 2745

You could use a second container (std::vector or std::set) with Iterators to your Elements, and sort it according to your needs.

Upvotes: 2

Related Questions