-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuicksort.py
More file actions
31 lines (25 loc) · 894 Bytes
/
Quicksort.py
File metadata and controls
31 lines (25 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class QSort:
def __init__(self, arr):
self.low = 0
self.arr = arr
self.high = len(self.arr)-1
#call 'self.sort' the properties to get the result
self.sort = self.recurve(self.low, self.high, self.arr)
#recurve to arrnge the list
def recurve(self, low, high, arr):
if low < high:
pi = self.part(low, high, arr)
self.recurve(low, pi-1, arr)
self.recurve(pi+1, high, arr)
return arr
#divide the list into parts by index
def part(self, low, high, arr):
i = low-1
for j in range(low, high):
if arr[j] < arr[high]:
i = i+1
arr[i], arr[j] = arr[j],arr[i]
arr[i+1], arr[high] = arr[high],arr[i+1]
return i+1
xyz = [10,30,80,90,40,50,70]
print(QSort(xyz).QSort)