def StartAlgorithm(): global data if algoMenu.get() == "Bubble Sort": bubbleSort(data, drawData, speedScale.get()) elif algoMenu.get() == "Insertion Sort": insertSort(data, drawData, speedScale.get()) elif algoMenu.get() == "Quick Sort": quickSort(data, 0, len(data) - 1, drawData, speedScale.get()) elif algoMenu.get() == "Merge Sort": mergeSort(data, drawData, speedScale.get()) elif algoMenu.get() == "Heap Sort": heapSort(data, drawData, speedScale.get()) drawData(data, ['#f274fc' for x in range(len(data))]) print("Starting Algorithm")
def shellSort1(ul): length = len(ul) w = 0 while w < length/3: # 步长H采用 Knuth提出的: 1 4 13 40 --- 即 i*3 + 1 w = w*3 + 1 # 选出小于length的最大步长 while w > 0: if length%w == 0: height = length / w else: height = length/w + 1 for i in range(w): l = [] for j in range(height): if i+w*j < length: l.append(ul[i+w*j]) newl = insertSort(l) for k in range(len(newl)): if i+k*w < length: ul[i + k*w] = newl[k] w = (w-1)/3 return ul
quickSort.quick_sort(data5,0,len(data5)) e5 = time.clock() print 'quick_sort:', e5-s5 s6 = time.clock() quickSort.qSort(data6) e6 = time.clock() print 'qSort:', e6-s6 s3 = time.clock() insertionSort.insertionSort(data3) e3 = time.clock() print 'insertionSort:', e3-s3 s8 = time.clock() insertionSort.insertSort(data8, 0, len(data8)) e8 = time.clock() print 'insertSort:', e8-s8 s4 = time.clock() selectionSort.selectionSort(data4) e4 = time.clock() print 'selectionSort:', e4-s4 s2 = time.clock() bubbleSort.bubble_sort(data2, 0, len(data2)) e2 = time.clock() print 'bubble_sort:', e2-s2