diff options
| author | Shinya Sato <shinnya.sato@gmail.com> | 2021-10-24 23:04:45 +0900 |
|---|---|---|
| committer | Shinya Sato <shinnya.sato@gmail.com> | 2021-10-24 23:04:45 +0900 |
| commit | 787dc13c837f0955fbd85b8f26a05d720d361333 (patch) | |
| tree | fec3abebb1e867e8b2239d7cf07b4c7d13ce0f81 /comparison/Python/qsort-800000.py | |
| parent | e607a57dfafb784c4e27da143214afb2ccd07fbf (diff) | |
| download | inpla-787dc13c837f0955fbd85b8f26a05d720d361333.tar.gz inpla-787dc13c837f0955fbd85b8f26a05d720d361333.zip | |
Upload the comparison directory
Diffstat (limited to '')
| -rw-r--r-- | comparison/Python/qsort-800000.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/comparison/Python/qsort-800000.py b/comparison/Python/qsort-800000.py new file mode 100644 index 0000000..9a75977 --- /dev/null +++ b/comparison/Python/qsort-800000.py @@ -0,0 +1,34 @@ +# 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 + +a = mkRandList(800000) +#a = mkRandList(8) +b = quickSort(a) +#print(a) |
