SHARE
TWEET

Untitled

a guest Jun 20th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. s1_name = "вставками"
  2. def simple_sort_1(A):
  3.     for i in range(1, len(A)):
  4.         j = A[i]
  5.         k = i - 1
  6.         while k >= 0 and A[k] > j:
  7.             A[k+1] = A[k]
  8.             k -= 1
  9.         A[k+1] = j
  10.     return  A  
  11.    
  12.  
  13. s2_name = "эффективный пузырек"
  14. def simple_sort_2(A):
  15.     for i in range(len(A) - 1):
  16.         Check = True
  17.         for j in range(len(A) - i - 1):
  18.             if A[j] > A[j+1]:
  19.                 A[j], A[j + 1] = A[j + 1], A[j]
  20.                 Check = False
  21.         if Check:
  22.             break
  23.     return A
  24.                    
  25.  
  26. s3_name = "расческой"
  27. def simple_sort_3(A):
  28.     gap = (len(A) * 10 // 13) if len(A) > 1 else 0
  29.     while gap:
  30.         if 8 < gap < 11:
  31.             gap = 11
  32.         swapped = False
  33.         for i in range(len(A) - gap):
  34.             if A[i + gap] < A[i]:
  35.                 A[i], A[i + gap] = A[i + gap], A[i]
  36.                 swapped = True
  37.         gap = (gap * 10 // 13) or swapped
  38.     return A
  39.  
  40. s4_name = "шейкерная"
  41. def simple_sort_4(A):
  42.     left = 0
  43.     right = len(A) - 1
  44.  
  45.     while left <= right:
  46.         for i in range(left, right, +1):
  47.             if A[i] > A[i + 1]:
  48.                 A[i], A[i + 1] = A[i + 1], A[i]
  49.         right -= 1
  50.  
  51.         for i in range(right, left, -1):
  52.             if A[i - 1] > A[i]:
  53.                 A[i], A[i - 1] = A[i - 1], A[i]
  54.         left += 1
  55.     return A
  56. def merge(A, left, mid, right):
  57.     i = left
  58.     j = mid + 1
  59.     AUX = []
  60.     while i <= mid and j <= right:
  61.         if A[i] < A[j]:
  62.             AUX.append(A[i])
  63.             i += 1
  64.         else:
  65.             AUX.append(A[j])
  66.             j += 1
  67.  
  68.     for k in range(i, mid + 1):
  69.         AUX.append(A[k])
  70.  
  71.     for k in range(j, right + 1):
  72.         AUX.append(A[k])
  73.     A[left:right + 1] = AUX
  74.     return A
  75.    
  76.    
  77. def mergeSortRec(A, left, right):
  78.     if left >= right:
  79.         return A
  80.     mid = (left + right) // 2
  81.     A = mergeSortRec(A, left, mid)
  82.     A = mergeSortRec(A, mid + 1, right)
  83.     A = merge(A, left, mid, right)
  84.     return A    
  85.  
  86. es_name = "слиянием"
  87. def effective_sort(A):
  88.     result = mergeSortRec(A, 0, len(A) - 1)
  89.     return A
  90.    
  91.    
  92.  
  93. def shell_sort(A):
  94.     gaps = [701, 301, 132, 57, 23, 10, 4, 1]
  95.     for step in gaps:
  96.         for i in range(len(A)):
  97.             elem = A[i]
  98.             index = i
  99.             while index >= step and elem < A[index - step]:
  100.                 A[index] = A[index - step]
  101.                 index = index - step
  102.             A[index] = elem
  103.     return A
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top