📄 genericsort.java
字号:
/*
* 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -