Amorf

Untitled

Oct 7th, 2021
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. c = 0;
  2. def QSort(left, right):
  3.     global c;
  4.     key = a[(left + right) // 2];
  5.     i = left;
  6.     j = right;
  7.     while True:
  8.     while a[i] < key:
  9.         i += 1;
  10.         c += 1;
  11.     while a[j] > key:
  12.         j -= 1;
  13.         c += 1;
  14.     if i <= j:
  15.         a[i], a[j] = a[j], a[i];
  16.         i += 1;
  17.         j -= 1;
  18.     if i > j:
  19.         break;
  20.     if left < j:
  21.         QSort(left, j);
  22.     if i < right:
  23.         QSort(i, right);
  24.     a = [5, 2, 6, 3, 4, 1]
  25.     QSort(0, 5);
  26.     print(a);
  27.  
Advertisement
Add Comment
Please, Sign In to add comment