SHARE
TWEET

Untitled

a guest Jun 20th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def counted_effective_sort_2(array):
  2.     global counter
  3.     counter += 1
  4.     array = quickSort(array, 0)
  5.     counter += 1
  6.     return array
  7. def partition(A, left, right):
  8.     global counter
  9.     counter += 1
  10.     i = left + 1
  11.     counter += 1
  12.     j = right
  13.     counter += len(A)
  14.     if len(A) == 0:
  15.         counter += 1
  16.         return A
  17.     counter += 1
  18.     while i <= j:
  19.         counter += 1
  20.         while A[i] < A[left] and i < right:
  21.             counter += 1
  22.             i += 1
  23.         while A[j] > A[left] and j > left:
  24.             counter += 1
  25.             j -= 1
  26.         counter += 1
  27.         if i >= j:
  28.             counter += 1
  29.             break
  30.         counter += 2
  31.         A[i], A[j] = A[j], A[i]
  32.         counter += 1
  33.         i += 1
  34.         counter += 1
  35.         j -= 1
  36.     counter += 2
  37.     A[left], A[j] = A[j], A[left]
  38.     counter += 1
  39.     return j
  40.  
  41.  
  42. def quickSort(A, left=0, right=None):
  43.     global counter
  44.     counter += 1
  45.     if right == None:
  46.         counter += len(A)
  47.         right = len(A) - 1
  48.     counter += len(A)
  49.     if len(A[left:right + 1]) < 2:
  50.         counter += 1
  51.         return A
  52.     counter += 1
  53.     p = partition(A, left, right)
  54.     counter += 1
  55.     quickSort(A, left, p - 1)
  56.     quickSort(A, p + 1, right)
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