16 фев 2020
conf
:
![](https://world79.spcs.bio/i/dark/acl/all_grey.png)
![(OFF)](https://world79.spcs.bio/i/dark/head/man_off.png?3)
![(S)](https://world79.spcs.bio/i/dark/colored/medal_silver.png)
binary-huinary search
хули я такой криворукий? ![:-(](https://world79.spcs.bio/i/dark/sm/gif/(.gif?0)
![:-(](https://world79.spcs.bio/i/dark/sm/gif/(.gif?0)
#include <stdio.h>
#define MAXSIZE 65535
int rec (int buf[], int, int, int);
static int count = 0;
int main () {
int buf[MAXSIZE] = {0};
for (int i = 0; i < MAXSIZE; i++) {
buf[i] = i;
}
printf ("%i\n", rec (buf, 0, MAXSIZE - 1, 256));
printf ("counts: %i\n", count);
return 0;
}
int rec (int buf[], int start, int end, int x) {
++count;
int middle = (buf[start] + buf[end]) / 2;
if (middle == x) {
return middle;
}
else if (middle > x) {
end = (start + end) / 2;
rec (buf, start, end, x);
}
else if (middle < x) {
start = (start + end) / 2;
rec (buf, start, end, x);
}
else {
fprintf(stderr, "Nothing Found.\n");
return 0;
}
}
![]() | ![]() | ![]() | ![]() |
Для добавления комментариев необходимо авторизоваться