-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathveryQuick.py
More file actions
37 lines (31 loc) · 868 Bytes
/
Copy pathveryQuick.py
File metadata and controls
37 lines (31 loc) · 868 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
import random
import time
def qsort1(list):
"""
Quicksort using list comprehensions
>>> qsort1<<docstring test numeric input>>
<<docstring test numeric output>>
>>> qsort1<<docstring test string input>>
<<docstring test string output>>
"""
if list == []:
return []
else:
pivot = list[0]
lesser = qsort1([x for x in list[1:] if x < pivot])
greater = qsort1([x for x in list[1:] if x >= pivot])
return lesser + [pivot] + greater
size = int(input("Enter the list size "))
x=random.sample(range(100000),size)
#I used this code instead to implement the array copying
# y = x[:] did not seem to work
y =[]
y.extend(x)
start = time.clock()
qsort1(x)
end = time.clock()
print("qsort1 time ",end-start)
start = time.clock()
y.sort()
end = time.clock()
print( "qsort of python time ",end-start)