Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def median(M, a, b):
- return M[(a + b) // 2]
- def first(M, a, b):
- return M[a]
- def last(M, a, b):
- return M[b]
- def __qsort(M, a, b, supf):
- r = 0
- c = supf(M, a, b)
- x, y = a, b
- while x < y:
- r += 3
- while M[x] < c:
- r += 1
- x += 1
- while M[y] > c:
- r += 1
- y -= 1
- if x <= y:
- M[x], M[y] = M[y], M[x]
- x += 1
- y -= 1
- if y > a:
- r += __qsort(M, a, y, supf)
- if x < b:
- r += __qsort(M, x, b, supf)
- return r
- def qsort(M, supf):
- return __qsort(M, 0, len(M) - 1, supf)
- A = list(map(int, input().split()))
- print(A)
- qsort(A, median)
- print(A)
- print(qsort(A, median), qsort(A, first), qsort(A, last))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement