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)
Пример #2
0
import SelectionSort

lst = [3, 4, 1, 2, 0]
SelectionSort.selectionSort(lst)
print(lst)
Пример #3
0
# 测试所有的排序算法的效率
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)
Пример #4
0
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)
Пример #5
0
import BucketSort


def init(tabl, size):
    random.seed()
    for i in range(0, size):
        tabl.append(random.randrange(100))
        
        
tabl = [30]
init(tabl, 30)

print(tabl)

print("Selection sort: \n")
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)