Not tested, but I think this is close to what you want:
class MissingNumbers {
private:
QList<int> numbers;
int count;
int index;
int last;
public:
MissingNumbers(const QSet<int> &numbersWeHave) {
numbers.fromSet(numbersWeHave);
qSort(numbers);
count = numbers.count();
index = 0;
last = 0;
}
int next() {
++last;
if (index >= count || last < numbers.at(index)) return last;
while (++index < count && numbers.at(index) - numbers.at(index-1) <= 1);
return last = numbers.at(index-1) + 1;
}
};
class MissingNumbers {
private:
QList<int> numbers;
int count;
int index;
int last;
public:
MissingNumbers(const QSet<int> &numbersWeHave) {
numbers.fromSet(numbersWeHave);
qSort(numbers);
count = numbers.count();
index = 0;
last = 0;
}
int next() {
++last;
if (index >= count || last < numbers.at(index)) return last;
while (++index < count && numbers.at(index) - numbers.at(index-1) <= 1);
return last = numbers.at(index-1) + 1;
}
};
To copy to clipboard, switch view to plain text mode
Bookmarks