first working demo

This commit is contained in:
2024-06-30 03:24:19 -04:00
parent 6dcf0f41e8
commit 12b74f12d4
5 changed files with 22 additions and 46 deletions

View File

@ -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();
}