There are better sort methods like quick sort or merge sort, but here is an example of a shell sort. This example is either from an old book or from some web article:
Code:
void shell_sort(int *a, int n)
{
int h, i, j, k; /* h is "gap" size */
for (h = n; h /= 2;){
for (i = h; i < n; i++){
k = a[i];
for (j = i; j >= h && k < a[j - h]; j -= h){
a[j] = a[j - h];
}
a[j] = k;
}
}
}
int main(int argc, char *argv[])
{
int a[] = {41, 53, 26, 0, 67, 98, 39, 84, 72, 15};
int n = sizeof(a) / sizeof(a[0]);
shell_sort(a, n);
return 0;
}
Wiki article about shell sort, including variations on the gap size (which is what "h" is used for in the above example):
http://en.wikipedia.org/wiki/Shell_sort