From 980f3b21a5373ba97de94152d19ea52860940400 Mon Sep 17 00:00:00 2001 From: pikachu49 Date: Wed, 25 Oct 2017 18:35:42 -0500 Subject: [PATCH] #21 added q-sort --- python/quicksort.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 python/quicksort.py diff --git a/python/quicksort.py b/python/quicksort.py new file mode 100644 index 0000000..cf73161 --- /dev/null +++ b/python/quicksort.py @@ -0,0 +1,17 @@ + +def quicksort(array=[12,4,5,6,7,3,1,15]): + less = [] + equal = [] + greater = [] + if len(array) > 1: + pivot = array[0] + for x in array: + if x < pivot: + less.append(x) + if x == pivot: + equal.append(x) + if x > pivot: + greater.append(x) + return sort(less)+equal+sort(greater) + else: + return array