forked from RiverWalter/AlgorithmCodes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
heapTTest.cpp
78 lines (78 loc) · 1.84 KB
/
heapTTest.cpp
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
//heapTTest.cpp
//测试堆操作的模板实现
#include "headers.h"
void heapTSortTest(int n)
{
ClsKEdge *e = new ClsKEdge[n];
for (int i=0; i<n; i++)
e[i].set(i, i, randRange(0, 99));
printf("原始数据列:\n");
for (int i=0; i<n; i++)
printf("%3d", e[i].cost);
printf("\n");
makeHeapMaxT(e, n);
printf("堆排序,从小到大:\n");
for (int i=0; i<n; i++)
printf("%3d", e[i].cost);
printf("\n");
for (int i=0; i<n; i++)
e[i].set(i, i, randRange(0, 99));
printf("原始数据列:\n");
for (int i=0; i<n; i++)
printf("%3d", e[i].cost);
printf("\n");
makeHeapMinT(e, n);
printf("堆排序,从大到小:\n");
for (int i=0; i<n; i++)
printf("%3d", e[i].cost);
printf("\n");
delete e;
}
void heapTTest(int n)
{
ClsKEdge *e = new ClsKEdge[n];
ClsKEdge e1;
for (int i=0; i<n; i++)
e[i].set(i, i, randRange(0, 99));
printf("原始数据列:\n");
for (int i=0; i<n; i++)
printf("%3d", e[i].cost);
printf("\n");
makeHeapMaxT(e, n);
printf("最大堆:\n");
for (int i=0; i<n; i++)
printf("%3d", e[i].cost);
printf("\n");
e1 = deleteTopMaxT(e, n);
printf("取顶元素: %d, n=%d\n", e1.cost, n);
for (int i=0; i<n; i++)
printf("%3d", e[i].cost);
printf("\n");
e1 = deleteTopMaxT(e, n);
printf("取顶元素: %d, n=%d\n", e1.cost, n);
for (int i=0; i<n; i++)
printf("%3d", e[i].cost);
printf("\n");
for (int i=0; i<n; i++)
e[i].set(i, i, randRange(0, 99));
printf("原始数据列:\n");
for (int i=0; i<n; i++)
printf("%3d", e[i].cost);
printf("\n");
makeHeapMinT(e, n);
printf("最小堆:\n");
for (int i=0; i<n; i++)
printf("%3d", e[i].cost);
printf("\n");
e1 = deleteTopMinT(e, n);
printf("取顶元素: %d, n=%d\n", e1.cost, n);
for (int i=0; i<n; i++)
printf("%3d", e[i].cost);
printf("\n");
e1 = deleteTopMinT(e, n);
printf("取顶元素: %d, n=%d\n", e1.cost, n);
for (int i=0; i<n; i++)
printf("%3d", e[i].cost);
printf("\n");
delete e;
}