genericsort.java
来自「关于java面向对象系统分析方面的课件」· Java 代码 · 共 55 行
JAVA
55 行
/*
* GenericValidate
* 2007
* 排序接口的默认实现类
*/
public class GenericSort implements Sort {
/**
* 比较的默认实现,不比较
*
* @param o1,o2
*/
public int compare(Object o1, Object o2) {
return 0;
}
/**
* 降序默认实现
*
* @param o
*/
public Object downSort(Object[] o) {
for (int i = 0; i < o.length - 1; i++) {
for (int j = i + 1; j < o.length; j++) {
if (this.compare(o[i], o[j]) < 0) {
Object temp = o[i];
o[i] = o[j];
o[j] = temp;
}
}
}
return o;
}
/**
* 升序默认实现
*
* @param o
*/
public Object upSort(Object[] o) {
for (int i = 0; i < o.length - 1; i++) {
for (int j = i + 1; j < o.length; j++) {
if (this.compare(o[i], o[j]) > 0) {
Object temp = o[i];
o[i] = o[j];
o[j] = temp;
}
}
}
return o;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?