用Java语言实现的各种排序,包括插入排序、冒泡排序、选择排序、Shell排序、快速排序、归并排序、堆排序、SortUtil等。 y%p&g
P6;L\9=H<
插入排序: o"K{^ L~u
t4h5R
package org.rut.util.algorithm.support; H<dm;cU
j @sd x)1+
import org.rut.util.algorithm.SortUtil; ,odjL6u
/** aZ#c_Q#gZ
* @author treeroot =OTwP
* @since 2006-2-2 }4\>q$8'
* @version 1.0 X=_N7!
*/ sLb[ZQ;j
public class InsertSort implements SortUtil.Sort{
`<q{8
j =[Td
/* (non-Javadoc) g7#_a6
* @see org.rut.util.algorithm.SortUtil.Sort#sort(int[])
,!PNfJA2
*/ dLG5yx\js
public void sort(int[] data) { %]RzC`NZ
int temp; rQ.j$U
for(int i=1;i for(int j=i;(j>0)&&(data[j] SortUtil.swap(data,j,j-1); Bglh}_X
} ytr~} M%
} <