def main(): """Start timer, sort, stop timer. write result to file""" #sizes = [10,50,100,500,1000,5000,10000,50000,100000,500000,1000000] b_times = [] i_times = [] m_times = [] q_times = [] size = 50000 #for size in sizes: for num in range(1,101): l = getlist("../lists/size" + str(size) + "/list" + str(num)) start = time.time() bubblesort(l) b_times.append((size,time.time() - start)) start = time.time() insertionsort(l) i_times.append((size,time.time() - start)) start = time.time() mergesort(l) m_times.append((size,time.time() - start)) start = time.time() quicksort(l) q_times.append((size,time.time() - start)) csv = "n,bubble,insertion,merge,quick\n" #for size in sizes: for i in range(100): csv += str(b_times[i][0]) + ',' + str(b_times[i][1]) + ',' csv += str(i_times[i][1]) + ',' + str(m_times[i][1]) + ',' csv += str(m_times[i][1]) + '\n' f = open("size50000-python.csv", 'w') f.write(csv) f.close()
def main(): """Try all of the size10 lists""" for i in range(1,101): l = getlist("../lists/size10/list" + str(i)) assert(sorted(l) == quicksort(l)) assert(sorted(l) == mergesort(l)) assert(sorted(l) == bubblesort(l)) assert(sorted(l) == insertionsort(l)) print("done")
def save_time(i, list): start = time.clock() time_bubble[i] = bubblesort(list[0]) # Tempo do bubblesort time_quick[i] = quicksort(list[1]) # Tempo do quicksort time_insert[i] = insertionsort(list[2]) # Tempo do insertionsort time_shell[i] = shellsort(list[3]) # Tempo do shellsort time_select[i] = selectionsort(list[4]) # Tempo do selectionsort time_heap[i] = heapsort(list[5]) # Tempo do heapsort time_merge[i] = mergesort(list[6]) # Tempo do merge end = time.clock() actualtime = end - start print "Tamanho de lista: {0} | Tempo para a execucao de todos algoritmos: {1}s".format(len(list[0]), actualtime) return # forca a saida
update_draw() if event.type == pygame.MOUSEBUTTONDOWN: return True else: window.blit(sort_image, frame) update_draw() while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() if cursor(bubblesort_frame, bubblesort_btn, bubblesortConfig_btn): bubblesort(speed, listlength) setTitle() # Reset setBoxes() elif cursor(quicksort_frame, quicksort_btn, quicksortConfig_btn): quicksort(speed, listlength) setTitle() # Reset setBoxes() elif cursor(mergesort_frame, mergesort_btn, mergesortConfig_btn): mergesort(speed, listlength) setTitle() # Reset setBoxes() elif cursor(insertionsort_frame, insertionsort_btn, insertionsortConfig_btn): # Algorithm not done # insertionsort() setTitle() # Reset setBoxes()