-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
126 lines (107 loc) · 2.86 KB
/
main.cpp
File metadata and controls
126 lines (107 loc) · 2.86 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
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
//
// main.cpp
// SortAlgorithm
//
// Created by xuwenyong on 15/11/23.
// Copyright © 2015年 Ack. All rights reserved.
//
#include <iostream>
#include "SortMethod.h"
void OutPutSortResult(int* result, int len, int* expected)
{
bool res=true;
printf(" ");
for (int i=0; i<len; ++i)
{
if (result[i]!=expected[i])
{
res=false;
printf(" ↑ ");
}
else
{
printf(" ");
}
}
if (res==false)
{
puts("\n!!!!!!!!!!!! Wrong Result!!!!!!!!!!!!\n");
}
else
{
puts("\nRight\n");
}
}
void Test(char* testName, int* nums, int len, int* expected)
{
int* copyArray=new int[len];
puts(testName);
puts("source data:");
PrintArray(nums, len);
CopyArray(nums,len,copyArray);
puts("BubbleSortResult:");
BubbleSort(copyArray,len);
PrintArray(copyArray, len);
OutPutSortResult(copyArray,len,expected);
CopyArray(nums,len,copyArray);
puts("QuickSortResult:");
QuickSort(copyArray,len);
PrintArray(copyArray, len);
OutPutSortResult(copyArray,len,expected);
CopyArray(nums,len,copyArray);
puts("InsertSortResult:");
InsertSort(copyArray,len);
PrintArray(copyArray, len);
OutPutSortResult(copyArray,len,expected);
CopyArray(nums,len,copyArray);
puts("BinaryInsertSortResult:");
BinaryInsertSort(copyArray,len);
PrintArray(copyArray, len);
OutPutSortResult(copyArray,len,expected);
CopyArray(nums,len,copyArray);
puts("ShellSortResult:");
ShellSort(copyArray,len);
PrintArray(copyArray, len);
OutPutSortResult(copyArray,len,expected);
CopyArray(nums,len,copyArray);
puts("SelectSortResult:");
SelectSort(copyArray,len);
PrintArray(copyArray, len);
OutPutSortResult(copyArray,len,expected);
CopyArray(nums,len,copyArray);
puts("HeapSortResult:");
HeapSort(copyArray,len);
PrintArray(copyArray, len);
OutPutSortResult(copyArray,len,expected);
CopyArray(nums,len,copyArray);
puts("MergeSortResult:");
MergeSort(copyArray,len);
PrintArray(copyArray, len);
OutPutSortResult(copyArray,len,expected);
delete[] copyArray;
}
void Test1()
{
int nums[]={};
int expected[]={};
Test("Test1",nums,sizeof(nums)/sizeof(int),expected);
}
void Test2()
{
int nums[]={1, 6, 3, 4, 9, 2, 5, 3, 4, 3};
int expected[]={1, 2, 3, 3, 3, 4, 4, 5, 6, 9};
Test("Test2",nums,sizeof(nums)/sizeof(int),expected);
}
void Test3()
{
int nums[]={10, 9, 5, 6, 9, 4, 2, 5, 7, 8, 9, 3, 11, 9, 3, 4, 7, 8, 5, 1};
int expected[]={1, 2, 3, 3, 4, 4, 5, 5, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9, 10, 11};
Test("Test3",nums,sizeof(nums)/sizeof(int),expected);
}
int main(int argc, const char * argv[])
{
Test1();
Test2();
Test3();
return 0;
}