Created
June 23, 2017 18:03
-
-
Save davit-Margvelashvili/f7e082eb2097c0a8ff92dbaa1061f018 to your computer and use it in GitHub Desktop.
Quicksort
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
import random | |
def Partition(Array, left, right): | |
pivot = Array[right] | |
while left < right: | |
while Array[left] < pivot: | |
left += 1 | |
while Array[right] > pivot: | |
right -= 1 | |
if left < right: | |
Array[left], Array[right] = Array[right], Array[left] | |
pivot, Array[right] = Array[right], pivot | |
return right | |
def Quicksort(Array, start, end): | |
if start < end: | |
splitpoint = Partition(Array, start, end) | |
Quicksort(Array, start, splitpoint - 1) | |
Quicksort(Array, splitpoint + 1, end) | |
return | |
Array = [random.randint(0, 100) for k in range(10)] | |
start = 0 | |
end = len(Array) - 1 | |
print("Unsorted Array", Array) | |
Quicksort(Array, start, end) | |
print("Sorted Array", Array) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment