-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathquickk_sort_2.py
More file actions
40 lines (28 loc) · 970 Bytes
/
quickk_sort_2.py
File metadata and controls
40 lines (28 loc) · 970 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
37
38
39
40
from threading import Thread
import threading
import time
import thread
def qsort(arr,low,high):
if low < high:
i = left - 1
pivot = arr[high]
for j in range(low,high):
if arr[j] <=pivot:
i = i+1
arr[i],arr[j] = arr[j],arr[i]
arr[i+1],arr[high] = arr[high],arr[i+1]
print("thread {0} is sorting {1} and pivot is {2}".format(threading.current_thread(), sets[left:right+1], pivot))
lthread = None
rthread = None
print "The array after pivot positioning ", sets
lthread = Thread(target = lambda: qsort(sets,left,j))
lthread.start()
rthread = Thread(target=lambda: qsort(sets,i,right))
rthread.start()
if lthread is not None: lthread.join()
if rthread is not None: rthread.join()
return sets
'''testing below'''
ls = [10,5,1,3,6,4,9,2,8,16,7]
res = qsort(ls, 0, len(ls) - 1)
print(res)