From 83bd9a57df93f65d80d34e44d458abb258fc8ba3 Mon Sep 17 00:00:00 2001 From: JacksonMateus <48231382+JacksonMateus@users.noreply.github.com> Date: Fri, 18 Oct 2019 16:48:55 -0300 Subject: [PATCH] Create gnome_sort.py --- allalgorithms/sorting/gnome_sort.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 allalgorithms/sorting/gnome_sort.py 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