This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "search.h" | |
int binary_search(int *a, int len, int x) { | |
int l = 0; | |
int r = len - 1; | |
while (l <= r) { | |
int m = l + (r - l) / 2; | |
if (a[m] == x) { | |
return m; | |
} else if (a[m] < x) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "sort.h" | |
static void swap(int *a, int *b) { | |
int temp = *a; | |
*a = *b; | |
*b = temp; | |
} | |
void bubblesort(int *a, int len) { | |
int i, j; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <time.h> | |
#include <sys/time.h> | |
#include "timeit.h" | |
double timeit(void (*f)()) { | |
struct timespec start, end; | |
clock_gettime(CLOCK_MONOTONIC, &start); | |
(*f)(); |