this is a big fix, not a small fix
This commit is contained in:
1 parent
ad3ce0bd48
commit
efe7783b78
2 files changed
+95
-16
No files matched your search
@@ -0,0 +1,25 @@
|
||||
// feed in a pointer to a function that takes 2 and returns (just like the )
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int cmpfunc(const void *a, const void *b)
|
||||
{
|
||||
const int *A = a, *B = b;
|
||||
return (*A > *B) - (*A < *B);
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
int a[13] = {1, 2, 3, 7, 3, 9, 11, 13, 42, -1, 4, 52, 10};
|
||||
qsort(a, 13, sizeof(int), cmpfunc);
|
||||
for (int i = 0; i < 13; i++)
|
||||
printf("%d ", a[i]);
|
||||
printf("\n");
|
||||
int at = 5;
|
||||
int *here = (int *)bsearch(&at, a, 13, sizeof(int), cmpfunc);
|
||||
if (here == NULL)
|
||||
printf("no %d ", at);
|
||||
else
|
||||
printf("is %d ", *here);
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user