|
Home
Download
Screenshots
Adding your sorts
Algorithms
-Bubble Sort
-Comb Sort
-Gnome Sort
-Heap Sort
-Insertion Sort
-Merge Sort
-Odd/Even Sort
-Quick Sort
-Quick Sort with Bubble Sort
-Radix Sort
-Rob (Random) Sort
-Selection Sort
-Shaker Sort
-Shear Sort
-Shell Sort
Donation:
|
Gnome Sort
Description:
The Gnome Sort algorithm is very simple. It works similarly to the
Insertion Sort, but has no nested loops. It simply moves forward
until something is out of order. When one is found, it swaps the
element back until it is in its place. Then, it continues
traversing from that point. Thus, it is highly inefficient.
Efficiency: O(N3)
Source:
public class GnomeSort: SortMethod
{
public override void sort(int[] list)
{
int i=0;
while(i<list.Length)
{
if(i==0||list[i]>=list[i-1])
i++;
else
swap(list,i,--i);
NumIterations++;
NumComparisons++;
pause(i);
}
}
public override string ToString()
{
return "Gnome Sort";
}
} |
|