Untitled
unknown
plain_text
a year ago
1.0 kB
2
Indexable
Never
def bubble_sort(arr): n = len(arr) for i in range(n): for j in range(0, n-i-1): if arr[j] > arr[j+1]: arr[j], arr[j+1] = arr[j+1], arr[j] def selection_sort(arr): n = len(arr) for i in range(n): min_index = i for j in range(i+1, n): if arr[j] < arr[min_index]: min_index = j arr[i], arr[min_index] = arr[min_index], arr[i] def insertion_sort(arr): n = len(arr) for i in range(1, n): key = arr[i] j = i - 1 while j >= 0 and key < arr[j]: arr[j + 1] = arr[j] j -= 1 arr[j + 1] = key input_list = [64, 34, 25, 12, 22, 11, 90] bubble_sorted = input_list.copy() selection_sorted = input_list.copy() insertion_sorted = input_list.copy() bubble_sort(bubble_sorted) print("Bubble Sort:", bubble_sorted) selection_sort(selection_sorted) print("Selection Sort:", selection_sorted) insertion_sort(insertion_sorted) print("Insertion Sort:", insertion_sorted)