Skip to content

Instantly share code, notes, and snippets.

@jakecraige
Last active October 26, 2015 23:19
Show Gist options
  • Save jakecraige/f5d5a7c3c18b0a08d431 to your computer and use it in GitHub Desktop.
Save jakecraige/f5d5a7c3c18b0a08d431 to your computer and use it in GitHub Desktop.
A sorting algorithm
void sort(int values[], int n)
{
for (int i = 0; i < n - 1; i++)
{
int j = i + 1;
while (values[i] > values[j])
{
int temp = values[j];
values[j] = values[i];
values[i] = temp;
j++;
}
}
}
@jakecraige
Copy link
Author

Given [6, 5, 3, 2, 4, 7, 9], printing out each step gives:

5632479
3652479
2653479
2563479
2365479
2356479
2346579
2345679

@jakecraige
Copy link
Author

Anyone know if this is a defined sorting algorithm? I was going for bubble sort but this is definitely not it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment