def main(): l = randomList() print("List size: ", len(l)) #BubbleSort start = time.time() BubbleSort.bubbleSort(l) end = time.time() print("BubbleSort: ", end - start) #InsertionSort start = time.time() InsertionSort.insertionSort(l) end = time.time() print("InsertionSort: ", end - start) #SelectionSort start = time.time() SelectionSort.selectionSort(l) end = time.time() print("SelectionSort: ", end - start) #ShellSort start = time.time() ShellSort.shellSort(l) end = time.time() print("ShellSort: ", end - start) #MergeSort start = time.time() MergeSort.mergeSort(l) end = time.time() print("MergeSort: ", end - start) #QuickSort start = time.time() QuickSort.quickSort(l, 0, len(l) - 1) end = time.time() print("QuickSort: ", end - start)
import QuickSort as q a = open("K1") b = {"stem": "", "normal_form": [], "frequency": ([], [])} for x in a: x = x.replace("\n", "").split(" ") b["stem"] = x[0] b["normal_form"].append(x[1]) b["frequency"][1].append(int(x[2])) [b["frequency"][0].append(x) for x in range(len(b["normal_form"]))] print(b["frequency"]) q.quickSort(b["frequency"], 1, True) print(b["frequency"]) q.quickSort(b["frequency"], 1, False) print(b["frequency"])
def test(name, number): A = [] for n in range(100, 10100, 100): for k in range(0, number): array = np.random.randint(0, 1000, n) array1 = array.copy() array2 = array.copy() array3 = array.copy() array4 = array.copy() array5 = array.copy() array6 = array.copy() start = time.time() comparing, changes = IS.insertionSort(array1) end = time.time() timer = end - start data = { "Tablica": n, "Czas": timer, "Zmiany": changes, "Porownania": comparing, "Nazwa": "Insert" } A.append(data) start = time.time() comparing, changes = MS.mergeSort(array2) end = time.time() timer = end - start data = { "Tablica": n, "Czas": timer, "Zmiany": changes, "Porownania": comparing, "Nazwa": "Merge" } A.append(data) start = time.time() comparing, changes = QS.quickSort(array3, 0, len(array3) - 1) end = time.time() timer = end - start data = { "Tablica": n, "Czas": timer, "Zmiany": changes, "Porownania": comparing, "Nazwa": "Quick" } A.append(data) start = time.time() comparing, changes = H.megreInsertSort(array4) end = time.time() timer = end - start data = { "Tablica": n, "Czas": timer, "Zmiany": changes, "Porownania": comparing, "Nazwa": "Hibrid10" } A.append(data) start = time.time() comparing, changes = DP.DualPivot(array, 0, len(array5) - 1) end = time.time() timer = end - start data = { "Tablica": n, "Czas": timer, "Zmiany": changes, "Porownania": comparing, "Nazwa": "Dual" } A.append(data) try: file = open(name, "w") json.dump(A, file, indent=3) except IOError: pass finally: file.close()
# 测试所有的排序算法的效率 import random import sys import BubbleSort import InsertSort import MergeSort import QuickSort import SelectionSort import ShellSort import threading import copy if __name__ == '__main__': # 快速排序递归可能溢出,这里设置大一点的值 # sys.setrecursionlimit(1000000) ls = [i for i in range(1, 10001)] random.shuffle(ls) # 复制,否则前面的排序会影响到后面的计算 ls1 = copy.copy(ls) ls2 = copy.copy(ls) ls3 = copy.copy(ls) ls4 = copy.copy(ls) ls5 = copy.copy(ls) # 挨个运行 BubbleSort.bubbleSort(ls) SelectionSort.selectionSort(ls1) InsertSort.insertSort(ls2) ShellSort.shellSort(ls3) MergeSort.mergeSort(ls4) QuickSort.quickSort(ls5)
def runquicktests(tests=mytests): for l0 in tests: QuickSort.quickSort(l0, 0, len(l0) - 1)
import QuickSort import MergeSort import InsertionSort import SelectionSort if __name__ == '__main__': l = [2, 7, 3, 1, 0, 11, 9, 8] QuickSort.quickSort(l) MergeSort.mergeSort(l) InsertionSort.insertionSort(l) SelectionSort.selectionSort(l) print(l)
def __FinalTransformation(self): """ Сортировка словаря :return: """ q.quickSort(self.__dct["frequency"], 1, True)
temp = SelectionSort.selectionSort(tabl) print(temp) print("\n\n") print("Insertion sort: \n") temp = InsertionSort.insertionSort(tabl) print(temp) print("\n\n") print("Bubble sort: \n") temp = BubbleSort.bubbleSort(tabl) print(temp) print("\n\n") print("Quick sort: \n") temp = QuickSort.quickSort(tabl) print(temp) print("\n\n") print("Merge sort: \n") temp = MergeSort.mergeSort(tabl) print(temp) print("\n\n") print("Heap sort: \n") temp = HeapSort.heapSort(tabl) print(temp) print("\n\n") print("Bucket sort: \n") temp = BucketSort.bucketSort(tabl)