#include <stdlib.h>
#include <string.h>
#include "report.h"
Defines | |
#define | COPY(a, b, size) |
Functions | |
void | insert (char *const pbase, size_t total_elems, size_t size, char *value, int(*cmp)(const void *, const void *)) |
Insertion Sort (from Wikipedia entry). | |
void | sortValues (void *const pbase, size_t total_elems, size_t size, int(*cmp)(const void *, const void *)) |
Sort the values using naive Insertion Sort implementation. | |
Variables | |
static char * | scratch |
copy value to be inserted into this spot so it won't be overwritten |
#define COPY | ( | a, | |||
b, | |||||
size | ) |
Value:
do \ { \ register size_t __size = (size); \ register char *__a = (a), *__b = (b); \ do \ { \ *__a++ = *__b++; \ } while (--__size > 0); \ } while (0)
void insert | ( | char *const | pbase, | |
size_t | total_elems, | |||
size_t | size, | |||
char * | value, | |||
int(*)(const void *, const void *) | cmp | |||
) |
Insertion Sort (from Wikipedia entry).
insert(array a, int length, value) { int i = length - 1; while (i >= 0 && a[i] > value) { a[i + 1] = a[i]; i--; }
a[i + 1] := value; }
insertionSort(array a, int length) { for (int i = 1; i < length; i++) insert(a, i, a[i]); }
void sortValues | ( | void *const | pbase, | |
size_t | total_elems, | |||
size_t | size, | |||
int(*)(const void *, const void *) | cmp | |||
) |
Sort the values using naive Insertion Sort implementation.
char* scratch [static] |
copy value to be inserted into this spot so it won't be overwritten
Algorithm Development Kit 1.0