Использование python: Измените программу «Таймер сортировки», чтобы собрать данные для заполнения электронной таблицы. Отрегулируйте переменную «size» в программе до размеров, указанных в электронной таблице. При необходимости замените метод сортировки Selection в программе на код для других методов сортировки. Округляйте все время с точностью до секунды:
import random
import time
import sys
sys.setrecursionlimit(2000)
def main():
size = 300000
list = []
for i in range(size):
list.append(random.randint(0, 100000 - 1))
print("Starting Sort ...")
startTime = time.time()
quickSort(list)
endTime = time.time()
print("Exection time for Selection Sort with", size, "values is: ",
endTime - startTime)
# The function for sorting the numbers
def quickSort(list):
quickSortHelper(list, 0, len(list) - 1)
def quickSortHelper(list, first, last):
if last > first:
pivotIndex = partition(list, first, last)
quickSortHelper(list, first, pivotIndex - 1)
quickSortHelper(list, pivotIndex + 1, last)
# Partition list[first..last]
def partition(list, first, last):
pivot = list[first] # Choose the first element as the pivot
low = first + 1 # Index for forward search
high = last # Index for backward search
while high > low:
# Search forward from left
while low <= high and list[low] <= pivot:
low += 1
# Search backward from right
while low <= high and list[high] > pivot:
high -= 1
# Swap two elements in the list
if high > low:
list[high], list[low] = list[low], list[high]
while high > first and list[high] >= pivot:
high -= 1
# Swap pivot with list[high]
if pivot > list[high]:
list[first] = list[high]
list[high] = pivot
return high
else:
return first
main()
Электронная таблица Excel с именем Sort Compare.xlsx выглядит следующим образом:
![spreadsheet](https://i.stack.imgur.com/dI5yd.jpg)