From 52d49b27476c8ede4f71c03f3b57020b62e0257a Mon Sep 17 00:00:00 2001 From: Anumeha Agrawal Date: Mon, 9 Oct 2017 16:13:50 +0530 Subject: [PATCH] Genome Sorting in Python --- genome_sort.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 genome_sort.py diff --git a/genome_sort.py b/genome_sort.py new file mode 100644 index 00000000..3b165211 --- /dev/null +++ b/genome_sort.py @@ -0,0 +1,24 @@ +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 + + +n=int(input()) +arr=[] +for i in range(n): + c=int(input()) + arr.append(c) + +arr = gnomeSort(arr, n) +print "Sorted sequence after applying Gnome Sort :", +for i in arr: + print(i)