-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort.py
More file actions
41 lines (33 loc) · 665 Bytes
/
Copy pathsort.py
File metadata and controls
41 lines (33 loc) · 665 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
41
import random
def swap(l,i,j):
temp=l[i]
l[i]=l[j]
l[j]=temp
def partition(l,i,j):
val=l[i]
h=i
for k in range(i+1,j+1):
if l[k]<val:
h=h+1
swap(l,h,k)
swap(l,i,h)
return h
def random_partition(l,i,j):
swap(l,i,random.randint(i,j))
return partition(l,i,j)
def quicksort(l,i,j):
if(i<j):
print l[i:j]
p=random_partition(l,i,j)
print p
quicksort(l,i,p-1)
quicksort(l,p+1,j)
mylist=[3,1,5,6,4,2,676,8,99,9,76,82,-1]
quicksort(mylist,0,len(mylist)-1)
for i in mylist:
print i,
def merge(l,i,m,j):
p=i
q=m+1
r=i
c=[]