forked from Ansh-Sarkar/Python-Data-Structures
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|