Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Count(object):
- comparison_count = 0
- swap_count = 0
- def __init__(self):
- return
- def quick_sort(a: list):
- count = Count()
- def qsort(fst, lst, c):
- if fst >= lst:
- return
- i, j = fst, lst
- border = a[random.randint(fst, lst)]
- while i <= j:
- while a[i] < border:
- i += 1
- while a[j] > border:
- j -= 1
- c.comparison_count += 1
- if i <= j:
- c.swap_count += 1
- a[i], a[j] = a[j], a[i]
- i, j = i + 1, j - 1
- qsort(fst, j, c)
- qsort(i, lst, c)
- qsort(0, len(a) - 1, count)
- print("\n\nБЫСТРАЯ\n")
- print(a)
- print(
- "Количество сравнений: " + str(count.comparison_count) + "\nКоличество перестановок: " + str(count.swap_count))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement