-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortAlgorithm.java
More file actions
33 lines (29 loc) · 956 Bytes
/
Copy pathSortAlgorithm.java
File metadata and controls
33 lines (29 loc) · 956 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 T1;
public abstract class SortAlgorithm {
public abstract void sort(Comparable[] objs);
protected void exchange(Comparable[] numbers, int i, int j){
Comparable temp;
temp = numbers[i];
numbers[i] = numbers[j];
numbers[j] = temp;
}
protected boolean less(Comparable one, Comparable other){
return one.compareTo(other) < 0;
}
protected void show(Comparable[] numbers){
int N = numbers.length;
int line = 0;
for(int i = 0; i < N; i++){
System.out.printf("%s ", numbers[i]);
line++;
if(line % 20 == 0) System.out.println();
}
System.out.println();
}
protected boolean isSorted(Comparable[] numbers){
int N = numbers.length;
for(int i = 0; i < N-1; i++)
if(numbers[i].compareTo(numbers[i+1]) > 0) return false;
return true;
}
}