Skip to content

Instantly share code, notes, and snippets.

@indriApollo
Created February 27, 2018 14:15
Show Gist options
  • Save indriApollo/cdbcc575a1e5759b0724430240616bbd to your computer and use it in GitHub Desktop.
Save indriApollo/cdbcc575a1e5759b0724430240616bbd to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdint.h>
static void shellSort(uint8_t* a, size_t n)
{
uint8_t t;
size_t h = n, i, j;
while(h /= 2)
{
for(i = h; i < n; i++)
{
t = a[i];
for(j = i; j >= h && t < a[j - h]; j -= h)
{
a[j] = a[j - h];
}
a[j] = t;
}
}
}
static void printArr(uint8_t* a, size_t n)
{
for(uint8_t i = 0; i<n; i++)
{
printf("%u ", a[i]);
}
printf("\n");
}
void main()
{
uint8_t a[10] = {25,64,1,225,63,88,44,9,74,114};
printArr(a, 10);
shellSort(a, 10);
printArr(a, 10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment