forked from argonautica/sorting-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGnomeSort.py
More file actions
19 lines (17 loc) · 686 Bytes
/
GnomeSort.py
File metadata and controls
19 lines (17 loc) · 686 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
def swapPositions(list,posA, posB):
list[posA], list[posB] = list[posB], list[posA]
return list
def gnomeSort(listToBeSorted):
position = 0
while position < len(listToBeSorted):
if position == 0 or listToBeSorted[position] >= listToBeSorted[position - 1]:
position = position +1
else:
swapPositions(listToBeSorted, position, position -1)
position = position -1
return listToBeSorted
print ("Input numbers you want to sort, seperated by spaces.")
inputList = [int(i) for i in input().split()]
print ("List to be sorted: {0}".format(inputList))
gnomeSort(inputList)
print ("The sorted list: {0}".format(inputList))