Add selection sort
This commit is contained in:
parent
abf965e7ce
commit
1f351ded8e
2 changed files with 35 additions and 4 deletions
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
#define SWAP(x, y, T) do { T SWAP = x; x = y; y = SWAP; } while (0)
|
||||
|
||||
void gnome_sort(int array[], int n) {
|
||||
void gnome_sort(int array[], int high) {
|
||||
int i = 0;
|
||||
while (i < n) {
|
||||
while (i < high) {
|
||||
if (array[i] > array[i+1]) {
|
||||
SWAP(array[i], array[i+1], int);
|
||||
if (i > 0) i--;
|
||||
|
|
@ -13,8 +13,8 @@ void gnome_sort(int array[], int n) {
|
|||
}
|
||||
}
|
||||
|
||||
void print_array(int array[], int n) {
|
||||
for (int i = 0; i < n; i++)
|
||||
void print_array(int array[], int high) {
|
||||
for (int i = 0; i <= high; i++)
|
||||
printf("%d ", array[i]);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue