-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path60_Quick_Sort.py
More file actions
60 lines (48 loc) · 1.33 KB
/
60_Quick_Sort.py
File metadata and controls
60 lines (48 loc) · 1.33 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class Sorting:
def __init__(self,arr):
self.arr = arr
if self.valuable() == False:
print("No values")
self.result()
def valuable(self):
return len(self.arr) > 0
def partition(self,low,high):
if self.valuable():
pivot= self.arr[high]
i = low -1
for j in range(low,high):
if self.arr[j] < pivot:
i += 1
self.swap(i,j)
self.swap(i+1,high)
return i+1
def swap(self,i,j):
temp = self.arr[i]
self.arr[i] = self.arr[j]
self.arr[j] = temp
def quickSort(self,low,high):
if self.valuable():
if low < high:
pi = self.partition(low,high)
self.quickSort(low,pi-1)
self.quickSort(pi+1,high)
def result(self):
if self.valuable():
n = len(self.arr)-1
self.quickSort(0,n)
print(self.arr)
class ISort:
def __init__(self):
self.result()
def Input(self):
a = []
while True:
n = input("Enter a number: ")
if n=="":
break
a.append(int(n))
return a
def result(self):
data = self.Input()
obj = Sorting(data)
o2 = ISort()