パッケージcom.ebiz.sort。 輸入java.text.SimpleDateFormatの。 輸入java.util.Date; / ** * @author YHJ * @Create 2019年7月29日8時56分 *插入排序 * / パブリック クラス挿入{ 公共 静的 ボイドメイン(文字列[]引数){ // INT [] ARR = {101,34,119、 1}。 INT [] ARR = 新しい int型 [80000 ]; 以下のために(int型、I <80000は、I = 0 iは++ ){ ARR [I] =(INT)(Math.random()* 800000 )。 } 文字列s = 新しい。SimpleDateFormatの( "YYYY-MM-DD HH:MM:SS")形式(新しい日付()); System.out.println( "排序前=" + S)。 getResult(ARR)。 列L = 新しいてSimpleDateFormat( "YYYY-MM-DD HH:MM:SS")形式(新しい日付())。 System.out.println( "排序后=" + L)。 // するSystem.out.println(Arrays.toString(ARR)); } パブリック 静的 ボイドのgetResult(INT [] ARR){ ため(int型私は++; iは<arr.length I = 1 ){ //挿入される数の定義 INT insertVal = ARR [I]; // インデックスの番号の前に INT。InsertIndex = -I 1 ; 一方(InsertIndex> = 0 && ARR [InsertIndex]> insertVal){ ARR [InsertIndex + +1 ] = ARR [InsertIndex]; InsertIndex - ; } // 。ループ端部が現在のインデックスの位置の前に挿入されることが見出さ 。ARR [InsertIndex + 1] = insertVal; } } }
完璧であるために...