MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / gnome_sort

Function gnome_sort

sorts/gnome_sort.py:3–19  ·  view source on GitHub ↗

Pure implementation of the gnome sort algorithm in Python.

(unsorted)

Source from the content-addressed store, hash-verified

1from __future__ import print_function
2
3def gnome_sort(unsorted):
4 """
5 Pure implementation of the gnome sort algorithm in Python.
6 """
7 if len(unsorted) <= 1:
8 return unsorted
9
10 i = 1
11
12 while i < len(unsorted):
13 if unsorted[i-1] <= unsorted[i]:
14 i += 1
15 else:
16 unsorted[i-1], unsorted[i] = unsorted[i], unsorted[i-1]
17 i -= 1
18 if (i == 0):
19 i = 1
20
21if __name__ == '__main__':
22 try:

Callers 1

gnome_sort.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected