Skip to content

Instantly share code, notes, and snippets.

View Ignavia-Snippets's full-sized avatar

Lars Reimann Ignavia-Snippets

View GitHub Profile
@Ignavia-Snippets
Ignavia-Snippets / search.c
Last active January 1, 2016 22:18
C: Searching
#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) {
@Ignavia-Snippets
Ignavia-Snippets / sort.c
Created January 1, 2014 15:05
C: Sorting
#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;
@Ignavia-Snippets
Ignavia-Snippets / timeit.c
Created December 28, 2013 14:31
C: Timeit
#include <time.h>
#include <sys/time.h>
#include "timeit.h"
double timeit(void (*f)()) {
struct timespec start, end;
clock_gettime(CLOCK_MONOTONIC, &start);
(*f)();