20 lines
570 B
Python
20 lines
570 B
Python
def bubblesort(arr):
|
|
for i in range(len(arr)):
|
|
for j in range(i + 1, len(arr)):
|
|
if arr[j] < arr[i]:
|
|
arr[i], arr[j] = arr[j], arr[i] # swap elements
|
|
|
|
return arr
|
|
|
|
print(bubblesort([1,2,3,4,5,6,10,6]))
|
|
|
|
def quicksort(arr):
|
|
if len(arr) <= 1:
|
|
return arr
|
|
else:
|
|
pivot = arr[len(arr)//2]
|
|
left = [x for x in arr if x < pivot]
|
|
middle = [x for x in arr if x == pivot]
|
|
right = [x for x in arr if x > pivot]
|
|
return quicksort(left) + middle + quicksort(right)
|