C/Data Structure Algorithm/Insertion Sort
The Insertion Sort
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
void insert(char *items, int count) {
register int i, b;
char t;
for(i=1; i < count; ++i) {
t = items[i];
for(b=i-1; (b >= 0) && (t < items[b]); b--)
items[b+1] = items[b];
// items[b+1] = t;
items[b] = t;
}
}
int main(void)
{
char s[255] = "asdfasdfasdfadsfadsf";
insert(s, strlen(s));
printf("The sorted string is: %s.\n", s);
return 0;
}