float position;
std::map<float, float> keys;
[...]
keys.insert(std::pair<float, float>(position, 0));
std::map<float, float>::iterator iterator = keys.find(position);
std::map<float, float>::iterator before = *(--iterator);
std::map<float, float>::iterator after = *(++(++iterator));
keys.erase(--iterator);
[C++] STL Algorithm Problem
Hello, i have a small STL algorithm problem. I have a sortet std::map<float, float>. Now I want to perform the folowing operation:
Operation: Search the element that would be before and after the element, if I would add it to the map.
The operation work, but is there a simpler way to do it (Without adding it to the map)?
Thanks
[Edited by - Fox32 on March 1, 2010 12:44:08 PM]
have a look at lower_bound and upper_bound
also your coe is buggy if map is empty or if the item is found very neat the beginning or end
also your coe is buggy if map is empty or if the item is found very neat the beginning or end
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement