-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsort.py
69 lines (51 loc) · 2 KB
/
sort.py
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
61
62
63
64
65
66
67
68
69
class quickSort:
##### WW WWW WW ####
##### WW WW WW WW ####
##### WW WW ####
#=========================#
# the input array will be changed forever!!!
#=========================#
sort_list=[] #the index enumerated with data list
input_list=[] #the input initial data list
def __init__(self):
pass
def sort(self,input_list=[]):
#print '>>>>>>>>>>>>'
#print 'qsort reporting...'
#print 'length of input array is: ',len(input_list)
sort_list=[]
high=len(input_list)-1
for i in range(0,high+1):
sort_list.append(i)
# print self.sort_list[high]
self.firstSort(input_list,sort_list,
0,high)
return sort_list
def firstSort(self,input_list,sort_list,low,high):
l=low;h=high
split=input_list[low]
while(l<h):
while(input_list[h]>split):
h-=1
if(l<h):
input_list[l]=input_list[h]
input_list[h]=split
sort_tmp=sort_list[l]
sort_list[l]=sort_list[h]
sort_list[h]=sort_tmp
l+=1
while(input_list[l]<split):
l+=1
if l<h :
input_list[h]=input_list[l]
input_list[l]=split
sort_tmp=sort_list[l]
sort_list[l]=sort_list[h]
sort_list[h]=sort_tmp
h-=1
self.loop(input_list,sort_list,l,h,low,high)
def loop(self,input_list,sort_list,l,h,low,high):
if l>low :
self.firstSort(input_list,sort_list,low,h-1)
if h<high:
self.firstSort(input_list,sort_list,l+1,high)