forked from inpla/inpla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqsort-260000.py
43 lines (34 loc) · 913 Bytes
/
qsort-260000.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
# Quicksort
import random
# https://stackoverflow.com/questions/23767787/python-implementation-of-quicksort-fails-to-sort-the-entire-array
def quickSort(arr):
less = []
pivotList = []
more = []
if len(arr) <= 1:
return arr
else:
pivot = arr[0]
for i in arr:
if i < pivot:
less.append(i)
elif i > pivot:
more.append(i)
else:
pivotList.append(i)
less = quickSort(less)
more = quickSort(more)
return less + pivotList + more
def mkRandList ( n ):
a=[]
for i in range(1,n+1):
a.insert(0, random.randint(0,10000))
return a
def validation(alist):
for i in range(len(alist)-1):
if (alist[i] > alist[i+1]):
return False
return True
a = mkRandList(260000)
b = quickSort(a)
print(validation(b))