Sorting
Sorting
list = [19,2,31,45,30,11,121,27]
insertion_sort(list)
print(list)
def bubblesort(list):
list = [19,2,31,45,6,11,121,27]
bubblesort(list)
print(list)
i = j = k = 0
def partition(arr,low,high):
i = ( low-1 ) # index of smaller element
pivot = arr[high] # pivot
arr[i+1],arr[high] = arr[high],arr[i+1]
return ( i+1 )
def selection_sort(input_list):
min_idx = idx
for j in range( idx +1, len(input_list)):
if input_list[min_idx] > input_list[j]:
min_idx = j
# Swap the minimum value with the compared value
l = [19,2,31,45,30,11,121,27]
selection_sort(l)
print(l)