Skip to content

Instantly share code, notes, and snippets.

@WizzyGeek
Created August 3, 2023 04:06
Show Gist options
  • Save WizzyGeek/98b94dff55a62cf8843c6500bb9e0c5c to your computer and use it in GitHub Desktop.
Save WizzyGeek/98b94dff55a62cf8843c6500bb9e0c5c to your computer and use it in GitHub Desktop.
#include"stdio.h"
#include"string.h"
size_t bisect(char **a, int len, char *elem) {
size_t hi = len - 1;
size_t lo = 0;
size_t mid;
while (1) {
mid = (hi + lo) >> 1;
int cmp = strcmp(a[mid], elem);
if (cmp == 0) return mid;
else if (cmp > 0) hi = mid - 1;
else lo = mid + 1;
if (hi == lo) {
return (strcmp(a[hi], elem) == 0) ? hi : -1;
}
}
}
int main() {
char store[5][5] = {"1234", "2345", "3456", "4567", "5678"};
char (*a)[5];
for (int i = 0; i < 5; i++) {
a[i] = store + i;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment