Skip to content

Instantly share code, notes, and snippets.

@irchimi
Created June 25, 2020 07:39
Show Gist options
  • Save irchimi/6fbec14ad30059492436c075199a9667 to your computer and use it in GitHub Desktop.
Save irchimi/6fbec14ad30059492436c075199a9667 to your computer and use it in GitHub Desktop.
GnomeSort in C++
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