first working demo
This commit is contained in:
@ -31,22 +31,15 @@ bool position::operator<(const position &other) const {
|
||||
return y < other.y || x < other.x;
|
||||
}
|
||||
|
||||
#include <iostream>
|
||||
|
||||
size_t find(const std::vector<position> &sorted_list,
|
||||
const position &target) {
|
||||
int l = 0;
|
||||
int r = sorted_list.size() - 1;
|
||||
// TODO: implement binary searching
|
||||
|
||||
while (l <= r) {
|
||||
int mid = l + (l + r) / 2;
|
||||
|
||||
if (target == sorted_list[mid])
|
||||
return mid;
|
||||
|
||||
if (target < sorted_list[mid])
|
||||
l = mid + 1;
|
||||
else
|
||||
r = mid - 1;
|
||||
}
|
||||
for (size_t i = 0; i < sorted_list.size(); ++i)
|
||||
if (sorted_list[i] == target)
|
||||
return i;
|
||||
|
||||
return sorted_list.size();
|
||||
}
|
||||
|
Reference in New Issue
Block a user