Find index of QVector by comparing an item
-
Hi,
I want to compare a item in a QVector and that will return index.
Ex. QVector {20,45,57,89} [0,1,2,3]
for value 46 it should say 2
for value 21 to 45 it should return 1
I can do this by using some loop conditions. But I want to know is there any inbuilt function for this.
-
-
yea that's what I was thinking i.e binary search but I was looking for any easy solution(s).
BS is in qt.
Link is "Binary search in QT":http://doc.trolltech.com/qq/qq15-qalgorithms.html
-
Well, I don't think you'll be able to use the built-in BS. (you are not looking for an exact match).
Alternatively, you can go wild :) and implement a Range class and overload some operators... but I think it would be too much hassle for something like this.
-
Such a list has been implemented by a troll before and is available here
http://qt.gitorious.org/qt-labs/itemviews-ng/blobs/master/src/qsectionspans_p.h