时间复杂度高:冒泡排序、选择排序。
时间复杂度低:基数排序、堆排序、希尔排序、归并排序、快速排序。

程序特点:
1、pyqt可视化;
2、开通多线程运行,可以同时对多个排序算法进行运行时间比较
3、可一次性生成一万个随机数,运用于测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
class SelectSort():
def __init__(self, arr):
self.start(arr)
def swap(self, arr, a, b):
temp = arr[a]
arr[a] = arr[b]
arr[b] = temp
def start(self, arr):
length = len(arr)
for i in range(length):
the_min = i
for j in range(i + 1, length):
if arr[j] < arr[the_min]:
the_min = j
self.swap(arr, the_min, i)
class QuickSort():
def __init__(self, arr):
self.start(arr, 0, len(arr) - 1)
def swap(self, arr, a, b):
temp = arr[a]
arr[a] = arr[b]
arr[b] = temp
def start(self, array, low, high):
if low > high:
return
pivot = low
left_p = low
right_p = high
while left_p < right_p:
while array[right_p] >= array[pivot] and left_p < right_p:
right_p -= 1
while array[left_p] <= array[pivot] and left_p < right_p:
left_p += 1
if left_p < right_p:
self.swap(array, right_p, left_p)
self.swap(array, pivot, left_p)
self.start(array, low, left_p - 1)
self.start(array, left_p + 1, high)
class ShellSort():
def __init__(self, arr):
self.start(arr)
def start(self, arr):
n = len(arr)
gap = int(n / 2)
while gap > 0:
for i in range(gap, n):
temp = arr[i]
j = i - gap
while j >= 0 and arr[j] > temp:
arr[j + gap] = arr[j]
j = j - gap
arr[j + gap] = temp
gap = int(gap / 2)
class HeapSort():
def __init__(self, arr):
self.start(arr)
def swap(self, arr, a, b):
temp = arr[a]
arr[a] = arr[b]
arr[b] = temp
def Percdown(self, arr, now, length):
replace = now * 2
while replace < length:
right_child = replace + 1
if right_child < length and arr[replace] < arr[right_child]:
replace = right_child
if arr[replace] > arr[now]:
self.swap(arr, replace, now)
now = replace
replace = now * 2
else:
break
def start(self, array):
length = len(array)
for i in range(length // 2, -1, -1):
self.Percdown(array, i, length)
for i in range(length - 1, -1, -1):
self.swap(array, 0, i)
self.Percdown(array, 0, i)
class RadixSort():
def __init__(self, arrx):
self.start(arrx)
def start(self, arr):
# buckets有十个桶
buckets = []
for i in range(10):
buckets.append([])
# 基数设置为6位
for i in range(6):
for j in arr:
buckets[(j // int(pow(10, i))) % 10].append(j)
# 清空 arr
arr.clear()
# 重新排序 并放入arr中
for k in buckets:
for z in k:
arr.append(z)
# 清空所有桶内容
for u in buckets:
u.clear()
class MergeSort():
def __init__(self, arr):
self.start(arr,0,len(arr)-1)
def start(self, array,low,high):
if low

运行结果