def time(a, sortname): import time from selection import selection from insertion import insertion from merge import mergeSort from quick import quickSort from heap import heapSort time_start = time.time() if sortname == 'Selection': selection(a) if sortname == 'Insertion': insertion(a) if sortname == 'Merge': mergeSort(a) if sortname == 'Quick': quickSort(a) if sortname == 'Heap': heapSort(a) time_end = time.time() return (time_end - time_start)
print(" ") print("Po sortowaniu babelkowym malejaco:") x.reverse() print(x) ######################################################################### ############################# QUICKSORT ############################### ######################################################################### if metoda == '2': # wypisanie #1 print(" ") print("Przed sortowaniem:") print(x) quick.quickSort(x, 0, len(x) - 1) # wypisanie #2 if kierunek == 'r': print(" ") print("Po sortowaniu szybkim rosnaco:") print(x) if kierunek == 'm': print(" ") print("Po sortowaniu szybkim malejaco:") x.reverse() print(x) ######################################################################### ############################ BUCKET SORT ############################## #########################################################################
elif op == 4: print("Você escolheu o algoritmo MergeSort\n") array_merg = array.copy() inicio = timeit.default_timer() result_merg = mergeSort(array_merg) fim = timeit.default_timer() result = fim - inicio print("Tempo de execução: {:.8f} \n".format(result)) elif op == 5: print("Você escolheu o algoritmo QuickSort\n") array_quic = array.copy() n = len(array_quic) inicio = timeit.default_timer() result_quic = quickSort(array_quic, 0, n - 1) fim = timeit.default_timer() result = fim - inicio print("Tempo de execução: {:.8f} \n".format(result)) elif op == 6: print("Você escolheu o algoritmo SelectionSort\n") array_selec = array.copy() inicio = timeit.default_timer() result_selec = selectionSort(array_selec) fim = timeit.default_timer() result = fim - inicio print("Tempo de execução: {:.8f} \n".format(result)) elif op == 7: print("Você escolheu o algoritmo ShellSort\n")
def plot(): '''Plottet die Laufzeiten der Sortierverfahren in einem Diagramm ''' fig = matplotlib.pyplot.figure() ax = fig.add_subplot(1, 1, 1) # Initialliste ogLst = listsGenerator(MAX_NUMBERS_IN_LIST) # Kopie fuer Bubblesort bubbleLst = copy.deepcopy(ogLst) # Kopie fuer InsertionSort insertionLst = copy.deepcopy(ogLst) # Kopie fuer SelectionSort selectionLst = copy.deepcopy(ogLst) # Kopie fuer MergeSort mergeLst = copy.deepcopy(ogLst) # Kopie fuer QuickSort quickLst = copy.deepcopy(ogLst) quickLst2 = copy.deepcopy(ogLst) # Funktion [x ; y] # x: Anzahl der Elemente -- y: Zeit zum sortieren ax.plot( [i for i in range(0, MAX_NUMBERS_IN_LIST)], [bubble.bubbleSort(j) for j in bubbleLst], '-', color='c', ) ax.plot([i for i in range(0, MAX_NUMBERS_IN_LIST)], [insertion.insertionSort(j) for j in insertionLst], '-', color='m') ax.plot( [i for i in range(0, MAX_NUMBERS_IN_LIST)], [selection.selectionSort(j) for j in selectionLst], '-', color='r', ) ax.plot( [i for i in range(0, MAX_NUMBERS_IN_LIST)], measureTime(mergeLst), '-', color='y', ) ax.plot( [i for i in range(0, MAX_NUMBERS_IN_LIST)], [quick.quickSort(j) for j in quickLst], '-', color='b', ) # ax.plot([i for i in range(0, MAX_NUMBERS_IN_LIST)], [quick_alt.quickSort(j) for j in quickLst2], '.') # Legende ax.set_title("Elemente in Liste im Intervall (0, %d)" % MAX_INTERV) ax.legend([ 'BubbleSort', 'InsertionSort', 'SelectionSort', 'MergeSort', 'QuickSort' ]) ax.set_xlabel('Anzahl Elemente in Liste') ax.set_ylabel('Sortierzeit in s') matplotlib.pyplot.show()
sortTime1 = 0.0 sortTime2 = 0.0 sortTime3 = 0.0 sortTime4 = 0.0 tmpTime = 0.0 countingSortErr = 0 for test in range(testset[0], testset[1] + 1): columnTitles.append("testset_" + str(size) + "_" + str(test)) file = "../../exemplaires/testset_" + str(size) + "_" + str(test) + ".txt" array = [] tempArray = read_integers(file) maxValues.append(max(tempArray)) # execute the algorithms # quickSort array = deepcopy(tempArray) tmpTime = round(quickSort(array) * 1000.0, 3) quickResults.append(tmpTime) sortTime1 += tmpTime # quickSort with seuil array = deepcopy(tempArray) tmpTime = round(quickSortSeuil(array) * 1000.0, 3) quickSeuilResults.append(tmpTime) sortTime2 += tmpTime # quickSort with seuil and random pivot for i in range(0, 10): array = deepcopy(tempArray) tmpTime += round(quickSortRandomSeuil(array) * 1000.0, 3) quickRandomSeuilResults.append(tmpTime/10.0) sortTime3 += (tmpTime/10.0)