Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
25 lines (22 loc) · 774 Bytes

File metadata and controls

25 lines (22 loc) · 774 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package Sort;
// 排序算法抽象类
public abstract class Sort<T extends Comparable<T>> {
// 返回两个数中较小的数
static boolean less(Comparable v, Comparable w)
{ return v.compareTo(w) < 0; }
// 交换数组中的两个元素
static void exch(Comparable[] a, int i, int j)
{ Comparable t = a[i]; a[i] = a[j]; a[j] = t; }
// 在单行中打印数组
public static void show(Comparable[] a) {
for (int i = 0; i < a.length; i++)
System.out.print(a[i] + " ");
System.out.println();
}
// 测试数组元素是否有序
public boolean isSorted(Comparable[] a) {
for (int i = 1; i < a.length; i++)
if (less(a[i], a[i-1])) return false;
return true;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.