all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
|
|
@ -0,0 +1,21 @@
|
|||
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
|
||||
|
||||
a = [4, 65, 2, -31, 0, 99, 83, 782, 1]
|
||||
a = quickSort(a)
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
def qsort(L):
|
||||
return (qsort([y for y in L[1:] if y < L[0]]) +
|
||||
L[:1] +
|
||||
qsort([y for y in L[1:] if y >= L[0]])) if len(L) > 1 else L
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
def qsort(list):
|
||||
if not list:
|
||||
return []
|
||||
else:
|
||||
pivot = list[0]
|
||||
less = [x for x in list if x < pivot]
|
||||
more = [x for x in list[1:] if x >= pivot]
|
||||
return qsort(less) + [pivot] + qsort(more)
|
||||
Loading…
Add table
Add a link
Reference in a new issue