Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -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)

View file

@ -0,0 +1,4 @@
def qsort(L):
return (qsort([y for y in L[1:] if y < L[0]]) +
[L[0]] +
qsort([y for y in L[1:] if y >= L[0]])) if len(L) > 1 else L

View file

@ -0,0 +1,8 @@
def qsort(list):
if not list:
return []
else:
pivot = list[0]
less = [x for x in list[1:] if x < pivot]
more = [x for x in list[1:] if x >= pivot]
return qsort(less) + [pivot] + qsort(more)

View file

@ -0,0 +1,8 @@
from random import *
def qSort(a):
if len(a) <= 1:
return a
else:
q = choice(a)
return qSort([elem for elem in a if elem < q]) + [q] * a.count(q) + qSort([elem for elem in a if elem > q])

View file

@ -0,0 +1,15 @@
def quickSort(a):
if len(a) <= 1:
return a
else:
less = []
more = []
pivot = choice(a)
for i in a:
if i < pivot:
less.append(i)
if i > pivot:
more.append(i)
less = quickSort(less)
more = quickSort(more)
return less + [pivot] * a.count(pivot) + more

View file

@ -0,0 +1,7 @@
def qsort(array):
if len(array) < 2:
return array
head, *tail = array
less = qsort([i for i in tail if i < head])
more = qsort([i for i in tail if i >= head])
return less + [head] + more

View file

@ -0,0 +1,17 @@
def quicksort(array):
_quicksort(array, 0, len(array) - 1)
def _quicksort(array, start, stop):
if stop - start > 0:
pivot, left, right = array[start], start, stop
while left <= right:
while array[left] < pivot:
left += 1
while array[right] > pivot:
right -= 1
if left <= right:
array[left], array[right] = array[right], array[left]
left += 1
right -= 1
_quicksort(array, start, right)
_quicksort(array, left, stop)