-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathmain.c
More file actions
59 lines (47 loc) · 1.78 KB
/
Copy pathmain.c
File metadata and controls
59 lines (47 loc) · 1.78 KB
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
#include "Sort.h"
int main() {
SqList a, test;
int i;
int comparetimes = 0, movetimes = 0;
int dk;
srand((unsigned)time(NULL));
a.length = test.length = 0;
for (i = 0; i < MAXSIZE; ++i) {
a.r[i] = test.r[i] = rand() % 100 + 1;
a.length++;
test.length++;
}
printf("初始化的数组为:\n");
Traverse(a);
printf("待排序的数组为:\n");
Traverse(test);
InsertSort(&test, &comparetimes, &movetimes);
printf("\n经过直接插入排序后的数组:\n");
Traverse(test);
printf("总比较次数为:%d\n总移动记录次数:%d\n两者次数之和:%d\n", comparetimes, movetimes, comparetimes + movetimes);
InitTestArrary(&a, &test, &comparetimes, &movetimes);
dk = 4;
ShellInsert(&test, dk, &comparetimes, &movetimes);
dk = 6;
ShellInsert(&test, dk, &comparetimes, &movetimes);
InsertSort(&test, &comparetimes, &movetimes);
printf("经过希尔排序后的数组:\n");
Traverse(test);
printf("总比较次数为:%d\n总移动记录次数:%d\n两者次数之和:%d\n", comparetimes, movetimes, comparetimes + movetimes);
InitTestArrary(&a, &test, &comparetimes, &movetimes);
BubbleSort(&test, &comparetimes, &movetimes);
printf("经过气泡排序后的数组:\n");
Traverse(test);
printf("总比较次数为:%d\n总移动记录次数:%d\n两者次数之和:%d\n", comparetimes, movetimes, comparetimes + movetimes);
InitTestArrary(&a, &test, &comparetimes, &movetimes);
QKSort(&test, 0, 19, &comparetimes, &movetimes);
printf("经过快速排序后的数组:\n");
Traverse(test);
printf("总比较次数为:%d\n总移动记录次数:%d\n两者次数之和:%d\n", comparetimes, movetimes, comparetimes + movetimes);
InitTestArrary(&a, &test, &comparetimes, &movetimes);
SelectSort(&test, &comparetimes, &movetimes);
printf("经过简单选择排序后的数组:\n");
Traverse(test);
printf("总比较次数为:%d\n总移动记录次数:%d\n两者次数之和:%d\n", comparetimes, movetimes, comparetimes + movetimes);
return 0;
}