冒泡排序算法的实现
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

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

用,就用的漂亮点。文章嘛,借花献佛喽。