Skip to content

Commit

Permalink
Merge pull request #223 from pramodbharti/master
Browse files Browse the repository at this point in the history
Added quicksort implementation in python
  • Loading branch information
ravivarshney01 authored Oct 11, 2018
2 parents 422e6db + 4660900 commit 277a57e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions data structures/quick_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
Here is the implementation of quicksort algorithm in python by Pramod Bharti
quick_sort() function takes an unsorted array and prints sorted array
"""
def quick_sort(arr):
if len(arr) <= 1:
return arr
pivot = arr[len(arr) // 2]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
return quick_sort(left) + middle + quick_sort(right)

print (quick_sort([5,2,8,3,9,12,43])) # This will print [2,3,5,8,9,12,43]

0 comments on commit 277a57e

Please sign in to comment.