diff --git a/quick_sort.py b/quick_sort.py new file mode 100644 index 0000000..ea86eae --- /dev/null +++ b/quick_sort.py @@ -0,0 +1,22 @@ +def partition(array, start, end): + pivot = array[start] + low = start + 1 + high = end + while True: + while low <= high and array[high] >= pivot: + high = high - 1 + while low <= high and array[low] <= pivot: + low = low + 1 + if low <= high: + array[low], array[high] = array[high], array[low] + else: + break + array[start], array[high] = array[high], array[start] + return high + #fuction of quick_sort +def quick_sort(array, start, end): + if start >= end: + return + p = partition(array, start, end) + quick_sort(array, start, p-1) + quick_sort(array, p+1, end)