From d1f2896e75b3c512ed5da24d344b81eea8335047 Mon Sep 17 00:00:00 2001 From: CayoViegas <50140892+CayoViegas@users.noreply.github.com> Date: Fri, 18 Oct 2019 16:33:14 -0300 Subject: [PATCH] Create GnomeSort.py --- allalgorithms/sorting/GnomeSort.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 allalgorithms/sorting/GnomeSort.py diff --git a/allalgorithms/sorting/GnomeSort.py b/allalgorithms/sorting/GnomeSort.py new file mode 100644 index 0000000..f900061 --- /dev/null +++ b/allalgorithms/sorting/GnomeSort.py @@ -0,0 +1,19 @@ +# -*- coding: UTF-8 -*- +# +# Gnome Sort Algorithm +# The All â–²lgorithms library for python +# +# Contributed by: Cayo Viegas +# Github: @CayoViegas +# + +def gnome(lista): + pivot = 0 + lista_length = len(lista) + while pivot < lista_length - 1: + if lista[pivot] > lista[pivot + 1]: + lista[pivot + 1], lista[pivot] = lista[pivot], lista[pivot + 1] + if pivot > 0: + pivot -= 2 + pivot += 1 +