-
Notifications
You must be signed in to change notification settings - Fork 1
/
sort_test.cpp
executable file
·186 lines (145 loc) · 3.66 KB
/
sort_test.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include <iostream>
#include "insert_sort.h"
#include "merge_sort.h"
#include "bubble_sort.h"
#include "maxheap_sort.h"
#include "fast_sort.h"
#include "count_sort.h"
using namespace std;
#define INPUT_LEN 20
int main(void)
{
int input[INPUT_LEN] = {10,9,8,7,6,5,4,3,3,6,4,8,5,6,4,5,7,2,1,11};
int output[INPUT_LEN];
int tmp[INPUT_LEN];
/** Insert sort */
insert_sort insert_sorter;
memmove( (void*)tmp, (void*)input, sizeof(input));
insert_sorter.sort(input, INPUT_LEN);
cout << "** Insert Sort **" << endl;
cout << "Input: " << endl;
for(int i = 0; i < INPUT_LEN ; ++i)
{
cout << tmp[i] << " ";
}
cout << endl;
cout << "Output: " << endl;
for(int i = 0; i < INPUT_LEN ; ++i)
{
cout << input[i] << " ";
}
cout << endl << endl;
memmove( (void*)input, (void*)tmp, sizeof(input));
/** bubble sort */
bubble_sort bubble_sorter;
memmove( (void*)tmp, (void*)input, sizeof(input));
bubble_sorter.sort(input, INPUT_LEN);
cout << "** Bubble Sort **" << endl;
cout << "Input: " << endl;
for(int i = 0; i < INPUT_LEN ; ++i)
{
cout << tmp[i] << " ";
}
cout << endl;
cout << "Output: " << endl;
for(int i = 0; i < INPUT_LEN ; ++i)
{
cout << input[i] << " ";
}
cout << endl << endl;
memmove( (void*)input, (void*)tmp, sizeof(input));
/** Count sort */
count_sort count_sorter;
count_sorter.sort(input, output, INPUT_LEN);
cout << "** Count Sort **" << endl;
cout << "Input: " << endl;
for(int i = 0; i < INPUT_LEN ; ++i)
{
cout << input[i] << " ";
}
cout << endl;
cout << "Output: " << endl;
for(int i = 0; i < INPUT_LEN ; ++i)
{
cout << output[i] << " ";
}
cout << endl << endl;
/** fast sort */
fast_sort fast_sorter;
memmove( (void*)tmp, (void*)input, sizeof(input));
fast_sorter.sort(input, 0, INPUT_LEN - 1);
cout << "** Fast Sort **" << endl;
cout << "Input: " << endl;
for(int i = 0; i < INPUT_LEN ; ++i)
{
cout << tmp[i] << " ";
}
cout << endl;
cout << "Output: " << endl;
for(int i = 0; i < INPUT_LEN ; ++i)
{
cout << input[i] << " ";
}
cout << endl << endl;
memmove( (void*)input, (void*)tmp, sizeof(input));
/** maxheap sort */
maxheap_sort maxheap_sorter;
memmove( (void*)tmp, (void*)input, sizeof(input));
maxheap_sorter.sort(input, INPUT_LEN);
cout << "** Maxheap Sort **" << endl;
cout << "Input: " << endl;
for(int i = 0; i < INPUT_LEN ; ++i)
{
cout << tmp[i] << " ";
}
cout << endl;
cout << "Output: " << endl;
for(int i = 0; i < INPUT_LEN ; ++i)
{
cout << input[i] << " ";
}
cout << endl << endl;
memmove( (void*)input, (void*)tmp, sizeof(input));
/** merge sort */
merge_sort merge_sorter;
memmove( (void*)tmp, (void*)input, sizeof(input));
merge_sorter.sort(input, 0, INPUT_LEN-1);
cout << "** Merge Sort **" << endl;
cout << "Input: " << endl;
for(int i = 0; i < INPUT_LEN ; ++i)
{
cout << tmp[i] << " ";
}
cout << endl;
cout << "Output: " << endl;
for(int i = 0; i < INPUT_LEN ; ++i)
{
cout << input[i] << " ";
}
cout << endl << endl;
memmove( (void*)input, (void*)tmp, sizeof(input));
/**
merge_sort merge_sorter;
bubble_sort bubble_sorter;
maxheap_sort maxheap_sorter;
fast_sort fast_sorter;
count_sort count_sorter;
// sorter.sort(input,10);
// sorter.sort_rev(input,10);
// sorter_2.sort(input,0,INPUT_LEN-1);
//sorter_3.sort(input,INPUT_LEN);
//maxheap_sorter.sort(input,INPUT_LEN);
// fast_sorter.sort(input,0,INPUT_LEN-1);
for(int i = 0; i < INPUT_LEN ; ++i)
cout << input[i] << " ";
cout << endl;
count_sorter.sort(input, output, INPUT_LEN);
for(int i = 0; i < INPUT_LEN ; ++i)
cout << input[i] << " ";
cout << endl;
for(int i = 0; i < INPUT_LEN ; ++i)
cout << output[i] << " ";
cout << endl;
*/
return 0;
}