Advertisement
Allena_Gorskaya

Квадратичные сортировки

Feb 25th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. def SelectionSort(A):
  2.     for i in range(0, len(A) - 1):
  3.         min_idx = i
  4.         for j in range(i + 1, len(A)):
  5.             if A[j] < A[min_idx]:
  6.                 min_idx = j
  7.         A[i], A[min_idx] = A[min_idx], A[i]
  8.  
  9. def InsertionSort(A):
  10.     for i in range(1, len(A)):
  11.         new_elem = A[i]
  12.         j = i - 1
  13.         while j >= 0 and A[j] > new_elem:
  14.             A[j + 1] = A[j]
  15.             j -= 1
  16.         A[j + 1] = new_elem
  17.  
  18. def BubbleSort(A):
  19.     for j in range(len(A) - 1, 0, -1):
  20.         for i in range(0, j):
  21.             if A[i] > A[i + 1]:
  22.                 A[i], A[i + 1] = A[i + 1], A[i]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement