sorts.gnome_sort

Gnome Sort Algorithm (A.K.A. Stupid Sort)

This algorithm iterates over a list comparing an element with the previous one. If order is not respected, it swaps element backward until order is respected with previous element. It resumes the initial iteration from element new position.

For doctests run following command: python3 -m doctest -v gnome_sort.py

For manual testing run: python3 gnome_sort.py

Attributes

user_input

Functions

gnome_sort(→ list)

Pure implementation of the gnome sort algorithm in Python

Module Contents

sorts.gnome_sort.gnome_sort(lst: list) list

Pure implementation of the gnome sort algorithm in Python

Take some mutable ordered collection with heterogeneous comparable items inside as arguments, return the same collection ordered by ascending.

Examples: >>> gnome_sort([0, 5, 3, 2, 2]) [0, 2, 2, 3, 5]

>>> gnome_sort([])
[]
>>> gnome_sort([-2, -5, -45])
[-45, -5, -2]
>>> "".join(gnome_sort(list(set("Gnomes are stupid!"))))
' !Gadeimnoprstu'
sorts.gnome_sort.user_input