From 9f0c837bb64ff4c1c4829941e7e9a77c30edcc3f Mon Sep 17 00:00:00 2001 From: John Karasinski Date: Wed, 3 Oct 2018 09:15:36 -0700 Subject: [PATCH] add python implementation of slow sort algorithm --- sort/Slow_Sort/python/Slow_Sort.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 sort/Slow_Sort/python/Slow_Sort.py diff --git a/sort/Slow_Sort/python/Slow_Sort.py b/sort/Slow_Sort/python/Slow_Sort.py new file mode 100644 index 0000000000..9a4b7862a1 --- /dev/null +++ b/sort/Slow_Sort/python/Slow_Sort.py @@ -0,0 +1,17 @@ +def slowsort(A, i, j): + (i, j) = (int(i), int(j)) + if i >= j: + return + m = (i + j) / 2 + m = int(m) + slowsort(A, i, m) + slowsort(A, m + 1, j) + if A[m] > A[j]: + A[m], A[j] = A[j], A[m] + slowsort(A, i, j - 1) + +test = [7, 6, 5, 9, 8, 4, 3, 1, 2, 0] +slowsort(test, 0, len(test) - 1) +print(test) +# >>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + \ No newline at end of file