diff --git a/allalgorithms/sorting/gnome_sort.py b/allalgorithms/sorting/gnome_sort.py new file mode 100644 index 0000000..c5eefc6 --- /dev/null +++ b/allalgorithms/sorting/gnome_sort.py @@ -0,0 +1,12 @@ +def gnomeSort( arr, n): + index = 0 + while index < n: + if index == 0: + index = index + 1 + if arr[index] >= arr[index - 1]: + index = index + 1 + else: + arr[index], arr[index-1] = arr[index-1], arr[index] + index = index - 1 + + return arr