diff --git a/sorting/README.md b/sorting/README.md index 9e4a7cc7..b7ed7f81 100644 --- a/sorting/README.md +++ b/sorting/README.md @@ -17,7 +17,8 @@ 1. [Bubble Sort](python/bubble-sort.py) 2. [Insertion Sort](python/insertion-sort.py) -2. [Selection Sort](python/selection-sort.py) +3. [Selection Sort](python/selection-sort.py) +4. [Quick Sort](python/quick-sort.py) ### Java diff --git a/sorting/python/quick-sort.py b/sorting/python/quick-sort.py new file mode 100644 index 00000000..d16cf5a8 --- /dev/null +++ b/sorting/python/quick-sort.py @@ -0,0 +1,12 @@ +def quickSort(arr): + n = len(arr) + if n == 1 or n == 0: + return arr + pi = 0 + left = [arr[i] for i in range(n) if arr[i] <= arr[pi] and i != pi] + right = [arr[i] for i in range(n) if arr[i] > arr[pi]] + return quickSort(left) + [arr[pi]] + quickSort(right) + + +arr = [10, 1, 6, 256, 2, 53, 235, 53, 1, 7, 23] +print("Sorted Array:", quickSort(arr))