-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathBaseSort.java
More file actions
33 lines (28 loc) · 752 Bytes
/
BaseSort.java
File metadata and controls
33 lines (28 loc) · 752 Bytes
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
package com.example.chapter2;
/**
* sort base class
* Created by siyehua on 2016/12/17.
*/
public class BaseSort<T> {
public static void sort(Comparable[] a) {
}
public static boolean less(Comparable v, Comparable w) {
return v.compareTo(w) < 0;
}
public static void exch(Comparable[] a, int i, int j) {
Comparable tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
public static boolean isSorted(Comparable[] a) {
for (int i = 1; i < a.length; i++) {
if (less(a[i], a[i - 1])) return false;
}
return true;
}
public static void show(Comparable[] a) {
for (int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
}
}