Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Quick sort Algorithm #12

Merged
merged 1 commit into from
Oct 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)