mirror of
https://github.com/RolandWH/ceesort.git
synced 2025-03-14 21:41:37 +00:00
binary search: remove superfluous variable
This commit is contained in:
parent
38deb15d4d
commit
063a229f3a
11
src/bsrch.c
11
src/bsrch.c
@ -14,16 +14,15 @@
|
|||||||
int bsrch(int target, int* arr, size_t n)
|
int bsrch(int target, int* arr, size_t n)
|
||||||
{
|
{
|
||||||
// TODO: Find a way to error if list is out of order
|
// TODO: Find a way to error if list is out of order
|
||||||
bool found = false;
|
int start = 0, end = (int)n - 1;
|
||||||
int start = 0, end = n - 1;
|
|
||||||
if (arr[start] > target || arr[end] < target) return -1;
|
if (arr[start] > target || arr[end] < target) return -1;
|
||||||
int mid = (start + end) / 2;
|
int mid = (start + end) / 2;
|
||||||
|
|
||||||
while (!found)
|
while (true)
|
||||||
{
|
{
|
||||||
if (arr[mid] == target) found = true;
|
if (arr[mid] == target) break;
|
||||||
if (start == end && !found) return -1;
|
if (start == end) return -1;
|
||||||
if (mid == end && !found) return -1;
|
if (mid == end) return -1;
|
||||||
else if (arr[mid] < target)
|
else if (arr[mid] < target)
|
||||||
{
|
{
|
||||||
start = mid + 1;
|
start = mid + 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user