-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickSort.py
More file actions
36 lines (34 loc) · 746 Bytes
/
quickSort.py
File metadata and controls
36 lines (34 loc) · 746 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
32
33
34
35
36
def QSort(arr, f, e):
if (f >= e):
return
pivot = partition(arr, f, e)
QSort(arr, f, pivot - 1)
QSort(arr, pivot + 1, e)
def partition(arr, f, e):
pivot = arr[e]
i = f - 1
for j in range(f, e):
if (arr[j] < pivot):
i += 1
temp = arr[i]
arr[i] = arr[j]
arr[j] = temp
i += 1
temp = arr[i]
arr[i] = arr[e]
arr[e] = temp
return i
arr = [5, 4, 8, 6, 7, 5, 4, 8, 6, 7]
print(arr)
QSort(arr, 0, 8)
print(arr)
def removeDuplicates(arr):
index = 0
B = [arr[0]]
for i in range(1, len(arr)):
if arr[i] != arr[i - 1]:
index += 1
B.append(arr[index])
return B
removeDuplicates(arr)
print(arr)