Quick Sort In Python (#35)

* Create quick-sort.py

* Update README.md
pull/50/head
Atin Bainada 2021-01-29 18:24:21 +05:30 committed by GitHub
parent fa3f0e084f
commit ccc78a79a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -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

View File

@ -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))