`
sunwch
  • 浏览: 165030 次
  • 性别: Icon_minigender_1
  • 来自: free-town
社区版块
存档分类
最新评论

插入排序

阅读更多
     public class InsertSort {

	public static void main(String[] args){
		int[] a = new int[]{52,254,21,10,2,5,89};
		int[] rs = swap(a);
		System.out.println("arraysResult:");
		for(int i=0;i<rs.length;i++){
			System.out.print(rs[i] + "\t");
		}
	}
	
	private static int[] swap(int[] a){
		for(int i=1;i<a.length;i++){
			int temp = a[i];
			int min = i;
			while(min>0 && a[min-1]>=temp){
				a[min] = a[min-1];
				--min;
			}
			a[min] = temp;
		}
		return a;
	}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics