-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathquicksort.py
More file actions
47 lines (40 loc) · 1.01 KB
/
quicksort.py
File metadata and controls
47 lines (40 loc) · 1.01 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
#!/usr/bin/env python
def partition(list, start, end):
pivot = list[end]
bottom = start-1
top = end
done = 0
while not done:
while not done:
bottom = bottom+1
if bottom == top:
done = 1
break
if list[bottom] > pivot:
list[top] = list[bottom]
break
while not done:
top = top-1
if top == bottom:
done = 1
break
if list[top] < pivot:
list[bottom] = list[top]
break
list[top] = pivot
return top
def quicksort(list, start, end):
if start < end:
split = partition(list, start, end)
quicksort(list, start, split-1)
quicksort(list, split+1, end)
else:
return
if __name__== "__main__":
import sys
list = map(int,sys.argv[1:])
start = 0
end = len(list)-1
quicksort(list,start,end)
import string
print string.join(map(str,list))