mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
style changes
This commit is contained in:
parent
0775bfc15e
commit
e24ab0aa7f
@ -4,7 +4,7 @@
|
|||||||
* A basic implementation of gnome sort algorithm.
|
* A basic implementation of gnome sort algorithm.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream> // for io operations
|
#include <iostream> // for io operations
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright 2020 @author beqakd
|
* Copyright 2020 @author beqakd
|
||||||
@ -25,13 +25,13 @@ template <class T> void gnomeSort(T arr[], int size) {
|
|||||||
if (size <= 1)
|
if (size <= 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int index = 0; // initialize some variables.
|
int index = 0; // initialize some variables.
|
||||||
while (index < size) {
|
while (index < size) {
|
||||||
// check for swap
|
// check for swap
|
||||||
if ((index == 0) || (arr[index] >= arr[index - 1])) {
|
if ((index == 0) || (arr[index] >= arr[index - 1])) {
|
||||||
index++;
|
index++;
|
||||||
} else {
|
} else {
|
||||||
std::swap(arr[index], arr[index - 1]); // swap
|
std::swap(arr[index], arr[index - 1]); // swap
|
||||||
index--;
|
index--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user