冒泡排序算法的实现
public class BubbleSort implements SortStrategy {
public void sort(Comparable[] obj) {
if (obj == null) {
throw new NullPointerException("The argument can not be null!");
}
Comparable tmp;
for (int i = 0 ;i < obj.length ;i++ ) {
for (int j = 0 ;j < obj.length - i - 1 ;j++ ) {
if (obj[j].compareTo(obj[j + 1]) > 0) {
tmp = obj[j];
obj[j] = obj[j + 1];
obj[j + 1] = tmp;
}
}
}
}
}
weiking
2006-04-06 22:00:10
评论:0
阅读:1221
引用:0
