Skip to content

Commit

Permalink
Added Quick sort Algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
strivercoder99 committed Oct 11, 2022
1 parent 5ce69a1 commit 668a5cd
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Sorting Algorithms/quicksort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'''
Online Python Compiler.
Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.
'''

def partition(array, low, high):


pivot = array[high]


i = low - 1


for j in range(low, high):
if array[j] <= pivot:


i = i + 1


(array[i], array[j]) = (array[j], array[i])


(array[i + 1], array[high]) = (array[high], array[i + 1])


return i + 1




def quickSort(array, low, high):
if low < high:

pi = partition(array, low, high)


quickSort(array, low, pi - 1)


quickSort(array, pi + 1, high)


data = [74,205,-19,32,-94,23,378,878,297,296,795,774,771]
print("Initial Array")
print(data)

size = len(data)

quickSort(data, 0, size - 1)

print('Resultant Array:')
print(data)

0 comments on commit 668a5cd

Please sign in to comment.