Skip to content

Instantly share code, notes, and snippets.

@codebrane
Created May 20, 2010 09:09
Show Gist options
  • Save codebrane/407376 to your computer and use it in GitHub Desktop.
Save codebrane/407376 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int ints[] = {4,3,7,2,23,444,53,23,6,-1,0};
int intsSize = sizeof(ints)/sizeof(int);
int buffer, count, shuffleCount;
for (count=1; count < intsSize; count++) {
if (ints[count] < ints[0]) {
buffer = ints[count];
for (shuffleCount = count; shuffleCount > 0; shuffleCount--) {
ints[shuffleCount] = ints[shuffleCount - 1];
}
ints[0] = buffer;
}
else {
while (ints[count] < ints[count-1]) {
buffer = ints[count-1];
ints[count-1] = ints[count];
ints[count] = buffer;
count--;
}
}
}
for (count=0; count < intsSize; count++) {
printf("%d ", ints[count]);
}
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment