def StartAlgorithm(): global data speed = int(speedScale.get()) if speed == 2: speed = 0.5 elif speed == 3: speed = 0.1 elif speed == 4: speed = 0.05 elif speed == 5: speed = 0.01 elif speed == 6: speed = 0.005 elif speed == 7: speed = 0.001 if selected_algo.get() == "Bubble Sort": bubble_sort(data, drawData, speed) elif selected_algo.get() == "Selection Sort": selection_sort(data, drawData, speed) elif selected_algo.get() == "Insertion Sort": insertion_sort(data, drawData, speed) elif selected_algo.get() == "Merge Sort": merge_sort(data, 0, len(data) - 1, drawData, speed) drawData(data, ['light green' for x in range(len(data))]) time.sleep(speed) elif selected_algo.get() == "Quick Sort": quick_sort(data, drawData, speed)
def StartAlgorithm(): global data speed = int(speedScale.get()) if speed == 2: speed = 1.5 elif speed == 3: speed = 0.1 elif speed == 4: speed = 0.05 elif speed == 5: speed = 0.01 elif speed == 6: speed = 0.005 elif speed == 7: speed = 0.001 search = int(searchEntry.get()) if selected_algo.get() == "Bubble Sort": bubble_sort(data, drawData, speed) elif selected_algo.get() == "Selection Sort": selection_sort(data, drawData, speed) elif selected_algo.get() == "Insertion Sort": insertion_sort(data, drawData, speed) elif selected_algo.get() == "Merge Sort": merge_sort(data, 0, len(data) - 1, drawData, speed) drawData(data, ['light green' for x in range(len(data))]) time.sleep(speed) elif selected_algo.get() == "Quick Sort": quick_sort(data, drawData, speed) elif algMenu.get() == 'Linear Search': linear_search(data, search, drawData, speedScale.get()) elif algMenu.get() == 'Binary Search': merge_sort(data, 0, len(data) - 1, drawData, speed) drawData(data, ['red' for x in range(len(data))]) binary_search(data, search, drawData, speedScale.get())
def quick_vs_selec_vs_insr(): lista = [] for i in range(40000): aleatorio = random.randint(0, 40000) lista.append(aleatorio) tempo = time.time() quick_sort(lista, 0, len(lista) - 1) fim = time.time() print("[QUICKSORT] 40000 (40 mil) inteiros Aleatorios\n[TEMPO] "+ str(fim - tempo)) lista = [] for i in range(40000): aleatorio = random.randint(0, 40000) lista.append(aleatorio) tempo = time.time() selection_sort(lista, len(lista)) fim = time.time() print("[SELECTIONSORT] 40000 (40 mil) inteiros Aleatorios\n[TEMPO] "+ str(fim - tempo)) lista = [] for i in range(40000): aleatorio = random.randint(0, 40000) lista.append(aleatorio) tempo = time.time() insertion_sort(lista, len(lista)) fim = time.time() print("[INSERTIONSORT] 40000 (40 mil) inteiros Aleatorios\n[TEMPO] "+ str(fim - tempo)) print("\n")
def StartAlgorithm(): global data if not data: return if select_algortiham.get() == 'Selection Sort': selection_sort(data, drawData, speedScale.get()) elif select_algortiham.get() == 'Bubble Sort': bubble_sort(data, drawData, speedScale.get()) elif select_algortiham.get() == 'Merge Sort': merge_sort(data, drawData, speedScale.get())
def StartAlgorithm(): global data if not data: return if algMenu.get() == 'Quick Sort': quick_sort(data, 0, len(data) - 1, drawData, speedScale.get()) drawData(data, ['green' for x in range(len(data))]) elif algMenu.get() == 'Bubble Sort': bubble_sort(data, drawData, speedScale.get()) elif algMenu.get() == 'Merge Sort': merge_sort(data, drawData, speedScale.get()) elif algMenu.get() == 'insertion Sort': insertion_sort(data, drawData, speedScale.get()) elif algMenu.get() == 'selection Sort': selection_sort(data, drawData, speedScale.get())
def quick_vs_selec_vs_insr(): data = [] for i in range(40000): random_num = random.randint(0, 40000) data.append(random_num) start = time.time() quick_sort(data, 0, len(data) - 1) end = time.time() print("[QUICKSORT] 40000 (40K) integers random numbers \n [start] " + str(end - start)) print("\n") data = [] for i in range(40000): random_num = random.randint(0, 40000) data.append(random_num) start = time.time() selection_sort(data, len(data)) end = time.time() print("[SELECTIONSORT] 40000 (40 mil) integers random_nums\n[start] " + str(end - start)) print("\n") data = [] for i in range(40000): random_num = random.randint(0, 40000) data.append(random_num) start = time.time() insertion_sort(data, len(data)) end = time.time() print("[INSERTIONSORT] 40000 (40 mil) integers random numbers \n[start] " + str(end - start)) print("\n")
sorted(lst) print(time.time() - x) x = time.time() heap_sort(lst) print(time.time() - x) x = time.time() merge_sort_recursion(lst) print(time.time() - x) x = time.time() insertion_sort(lst) print(time.time() - x) x = time.time() selection_sort(lst) print(time.time() - x) x = time.time() bubble_sort(lst) print(time.time() - x) x = time.time()
inp_arr = [] if sel > 0: file_nm = input("Enter csv filename with data: ") if file_nm == "": file_nm = "sortedfil.csv" with open(file_nm, "r") as f: file_dat = f.readlines() for sublist in file_dat: for nums in sublist.split(","): inp_arr.append(int(nums)) start_time = time.time() if sel == 1: sorted_array = ss.selection_sort(inp_arr) elif sel == 2: sorted_array = ins.insertion_sort(inp_arr) elif sel == 3: sorted_array = bs.bubble_sort(inp_arr) elif sel == 4: sorted_array, invcount = ms.merge_sort(inp_arr, 0) elif sel == 5: qs.quick_sort(inp_arr, 0, len(inp_arr) - 1) elif sel == 6: is_sort = input("Is the input already sorted(Y/N): ") if not is_sort.upper().strip() == "Y": sorted_arr, x = ms.merge_sort(inp_arr, 0) start_time - time.time()
def test_selectionsort(self, lst): self.assertEqual(selection_sort(lst), sorted(lst))
def start_selection(event, canvas, sort, i_count): global arr, count count = 0 i_count["text"] = f"{count}" selection_sort(arr, draw_data, canvas, sort, count, i_count)