Sorting/ValueBased/insertion_all_copy.c File Reference

Insertion Sort implementation over value-based arrays. Contains Insertion Sort implementation for value-based arrays. No special optimizations, so each transposition results in a single swap of elements. More...

#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


Detailed Description

Insertion Sort implementation over value-based arrays. Contains Insertion Sort implementation for value-based arrays. No special optimizations, so each transposition results in a single swap of elements.

Author:
George Heineman
Date:
6/15/08

Define Documentation

#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)


Function Documentation

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.


Variable Documentation

char* scratch [static]

copy value to be inserted into this spot so it won't be overwritten

Algorithm Development Kit 1.0