-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
77 lines (71 loc) · 2.15 KB
/
Main.java
File metadata and controls
77 lines (71 loc) · 2.15 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
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
int N = 5;
int[][] testCase = new int[N][];
testCase[0] = new int[]{5,4,3,2,1};
testCase[1] = new int[]{3,3,3,3,3};
testCase[2] = new int[]{2};
testCase[3] = new int[]{1,20,1000,30,40,100000,50};
testCase[4] = new int[]{1,2,3,4,5};
int[][] result = new int[N][];
result[0] = new int[]{1,2,3,4,5};
result[1] = new int[]{3,3,3,3,3};;
result[2] = new int[]{2};
result[3] = new int[]{1,20,30,40,50,1000,100000};
result[4] = new int[]{1,2,3,4,5};
Solution s = new Solution();
boolean flag = isOk(testCase,result);
System.out.println("最终结果: "+ flag);
}
//测试多组测试数据是否正确
static boolean isOk(int[][] testCase,int [][] result){
if(testCase==null && result==null) return true;
if(testCase==null || result==null) return false;
if(testCase.length!=result.length) return false;
for(int i=0; i<result.length;i++){
//冒泡排序算法
//new Solution().bubbleSort(testCase[i]);
//插入排序算法
//new Solution().insertSort(testCase[i]);
//选择排序
//new Solution().selectSort(testCase[i]);
//快速排序
new Solution().quickSort(testCase[i]);
boolean flag = isSame(testCase[i],result[i]);
System.out.println("case: "+ i);
if(flag){
System.out.println("flag: "+ flag);
System.out.print("正确结果:");
print(testCase[i]);
}else{
System.out.println("flag: "+flag);
System.out.print("期待结果:");
print(result[i]);
System.out.print("你的结果:");
print(testCase[i]);
return false;
}
System.out.println("-------------------------------");
}
return true;
}
//判断一组测试数据是否正确
static boolean isSame(int A[],int B[]){
if(B==null && A==null) return true;
if(B==null || A==null) return false;
if(A.length!=B.length){
return false;
}
for(int i=0;i<A.length;i++){
if(A[i]!=B[i]) return false;
}
return true;
}
static void print(int[] A){
for(int i=0;i<A.length;i++){
System.out.print(A[i]+" ");
}
System.out.println();
}
}