-
Notifications
You must be signed in to change notification settings - Fork 0
/
1010.py
70 lines (55 loc) · 1.27 KB
/
1010.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
70
import random
Target = []
Lower = 0
Upper = 100
Count = 15
for i in xrange(Count):
Target.append(random.randint(Lower, Upper));
# def bubblesort(a) :
# count = 1
# for i in range(0,len(a)):
# for j in range(i+1, len(a)):
# if(count % 10 == 1 and count % 100 != 11) :
# print "....",count,"st comparison...."
# elif(count % 10 == 2 and count % 100 != 12) :
# print "....",count,"nd comparison...."
# else:
# print "....",count,"th comparison...."
# print a[i],"(",i,") and ",a[j],"(",j,") comparison"
# if(a[i] > a[j]) :
# temp = a[i]
# a[i] = a[j]
# a[j] = temp
# count = count +1
# return a
# print bubblesort(Target)
cnt = 1
depth = 0
def quickquick(a) :
global cnt
global depth
length = len(a)
if(len(a)<=1) :
depth = depth -1
return a
#print cnt,":", a, "%-s" % (depth)
print "%2d : %-60s Depth: %d" %(cnt, a, depth)
cnt = cnt + 1
pivot = a[0]
less =[]
greater = []
pivot_list = []
for i in range(length) :
if a[i] > pivot :
greater.append(a[i])
elif a[i] == pivot :
pivot_list.append(a[i])
else :
less.append(a[i])
depth = depth + 1
less = quickquick(less)
depth = depth + 1
greater = quickquick(greater)
depth = depth - 1;
return less + pivot_list + greater
print "Output : %s" %quickquick(Target)