存档

文章标签 ‘排序算法’

各种排序算法java实现

2010年6月28日
43 views 没有评论

插入排序:
 

  1.  
  2. package org.rut.util.algorithm.support;
  3. import org.rut.util.algorithm.SortUtil;
  4.  
  5. public class InsertSort implements SortUtil.Sort{
  6.     /* (non-Javadoc)
  7.      * @see org.rut.util.algorithm.SortUtil.Sort#sort(int[])
  8.      */
  9.     public void sort(int[] data) {
  10.         int temp;
  11.         for(int i=1;i<data.length;i++){
  12.             for(int j=i;(j>0)&amp;&amp;(data[j]<data[j-1]);j–){
  13.                 SortUtil.swap(data,j,j-1);
  14.             }
  15.         }        
  16.     }
  17. }
  18.  
阅读全文…

java