码迷,mamicode.com
首页 > 编程语言 > 详细

插入排序

时间:2019-09-23 10:07:30      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:string   static   ati   排序   temp   sort   system   code   --   

package com.datastack.search; import java.util.Arrays; //插入排序 public class InsertSort { public static void main(String[] args) { int[] arr = new int[]{1,3,5,2,5,5,512,231,123,556,669}; insertSort(arr); System.out.println(Arrays.toString(arr)); } public static void insertSort(int[] arr){ for(int i=1;i<arr.length;i++){ int temp = arr[i]; int left = i-1; while(left>=0 && arr[left] > temp){ arr[left+1] = arr[left]; left--; } arr[left+1] = temp; } } }

插入排序

标签:string   static   ati   排序   temp   sort   system   code   --   

原文地址:https://blog.51cto.com/12720374/2440032

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!