samedi 27 juin 2015

How to adapt map in order to find the nearest smaller object?

For example, if my map is from integers to doubles and contains :

  • 2 -> 3.4
  • 3 -> 87.3
  • 5 -> 0.0
  • 12 -> 43.4

When I search 4, I have to obtain 87.3, since 3 is the nearest smaller key which is in the map. When I search 11, I have to obtain 0.0.

This could be done with a balanced tree. But I don't want implement a balanced tree, may be there is a way to do this directly using STL ?

Aucun commentaire:

Enregistrer un commentaire