Created
June 25, 2020 07:39
-
-
Save irchimi/6fbec14ad30059492436c075199a9667 to your computer and use it in GitHub Desktop.
GnomeSort in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void GnomeSort(int arr[], int count) { | |
int index = 1; | |
int nextIndex = index + 1; | |
while (index < count) | |
{ | |
if (arr[index - 1] < arr[index]) | |
{ | |
index = nextIndex; | |
nextIndex++; | |
} | |
else | |
{ | |
Swap(arr[index - 1], arr[index]); | |
index--; | |
if (index == 0) | |
{ | |
index = nextIndex; | |
nextIndex++; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment