(I have changed this answer since the asker clarified that his ranges do not overlap. ).
(I have changed this answer since the asker clarified that his ranges do not overlap. ) If the set of ranges does not change, you can use a sorted vector and binary search, as suggested in ravenspoint's answer. If the set of ranges changes over time, you might still use a sorted vector, or you might want to use a std::map.
You need to try both and see which one is faster in that case.
I still find problems with actually finding whether an element is present in a range. The problem is it should be found either its present in anyone of the range strictly or not?! No mix and matching the ranges.
– Dumb yesterday.
Assuming the ranges do not overlap: Store each range in a simple structure range { int low; int high; string name; } Store the ranges in a sorted vector, by low. Find required range using binary search for largest low less than target.
S range1 and range3 examples overlap. – rob mayoff Dec 14 at 21:35 Apparently they do not overlap. The question is confusing.
I have edited question so example does not overlap – ravenspoint Dec 15 at 13:59 Sorry for the mistake in the question. You have edited before I could. I dint notice the overlap.
– Dumb Dec 15 at 21:51.
Just dump all the values , starting and ending into a vector or array, and then sort it. Since the ranges don't overlap, once the array is sorted, you will have start, stop,start,stop,etc.. then, you could use a binary search to find the index of the vector. Then its just a question of whether its odd or even assuming, you are getting the ranges from the stream vector ranges; int n; while(in >> n){ ranges.
Push_back(n); } sort(ranges.begin(),ranges.end()) int x; cout > x; int index = binary_search(x,ranges); if(index % 2){ cout = f) return s; int n = (f-s)/2 + s; if(vecn == x)return n; if(vecn.
I need to find whether the element is present in a range and it should not mix and matched and it should be strictly either present or not. – Dumb yesterday.
With B+ tree, the fan-out would be small and search would be fast too.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.