Skip to content

Instantly share code, notes, and snippets.

@progapandist
Created June 1, 2015 11:15
Show Gist options
  • Save progapandist/ae7ce3a1ef2d397503cd to your computer and use it in GitHub Desktop.
Save progapandist/ae7ce3a1ef2d397503cd to your computer and use it in GitHub Desktop.
void insertsort(int array[], int size)
{
int sorted = 1;
while (sorted < size - 1)
{
for (int i = 0; i <= sorted; i++)
{
if (array[i] > array[i + 1])
{
int smallest = array[i + 1];
int temp;
for (int j = i; j >= 0; j--)
{
while (smallest < array[j])
{
temp = array[j + 1];
array[j + 1] = array[j];
array[j] = temp;
}
}
}
}
sorted++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment