-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarClient.java
More file actions
78 lines (61 loc) · 1.52 KB
/
CarClient.java
File metadata and controls
78 lines (61 loc) · 1.52 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
package Lec50;
import java.util.*;
public class CarClient {
public static void main(String[] args) {
// TODO Auto-generated method stub
// int [] arr = new int [7];
Cars[] ar = new Cars[5];
ar[0] = new Cars(200, 10, "White");
ar[1] = new Cars(1000, 20, "Black");
ar[2] = new Cars(345, 3, "Yellow");
ar[3] = new Cars(34, 89, "Grey");
ar[4] = new Cars(8907, 6, "Red");
Display(ar);
System.out.println("*********************");
// Sort(ar, new CarCompareterSpeed());
/// Sort(ar, new CarCOmparaterPrice());
// Sort(ar, new CarComparaterColor());
Arrays.sort(ar, new Comparator<Cars>() {
@Override
public int compare(Cars o1, Cars o2) {
// TODO Auto-generated method stub
return o2.price - o1.price;
}
});
Display(ar);
}
public static void Display(Cars[] ar) {
for (int i = 0; i < ar.length; i++) {
System.out.println(ar[i]);
}
}
// public static <T extends Comparable<T>> void Sort(T[] arr) {
//
// // pass
// for (int turn = 1; turn < arr.length; turn++) {
//
// for (int i = 0; i < arr.length - turn; i++) {// 6-1
// if (arr[i].compareTo(arr[i + 1]) > 0) {
// T t = arr[i];
// arr[i] = arr[i + 1];
// arr[i + 1] = t;
// }
//
// }
//
// }
//
// }
public static <T> void Sort(T[] arr, Comparator<T> camp) {
// pass
for (int turn = 1; turn < arr.length; turn++) {
for (int i = 0; i < arr.length - turn; i++) {// 6-1
if (camp.compare(arr[i], arr[i + 1]) > 0) {
T t = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = t;
}
}
}
}
}