GnomeSort

Gnome Sort.

Based on the technique used by the standard Dutch Garden Gnome. Looks at the current and previous element; if they are in the right order it steps forward, otherwise it swaps them and steps backward. Boundary conditions: no previous element steps forward, no next element means done.

— "Gnome Sort - The Simplest Sort Algorithm". Dickgrune.com

Functions

Link copied to clipboard
fun <T : Comparable<T>> sort(array: Array<T>)

Sorts the array in ascending natural order.

fun sort(array: IntArray)

Sorts an IntArray in ascending order.

fun <T> sort(array: Array<T>, comparator: Comparator<T>)

Sorts the array using the given comparator.