日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java 二分排序法

發(fā)布時間:2023/12/9 java 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java 二分排序法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
public class BinarySort { public static void binarySort(int[] source) { int i, j; int high, low, mid; int temp; for (i = 1; i < source.length; i++) { // 查找區(qū)上界 low = 0; // 查找區(qū)下界 high = i - 1; //將當前待插入記錄保存在臨時變量中 temp = source[i]; while (low <= high) { // 找出中間值 // mid = (low + high) / 2; mid = (low + high) >> 1; //如果待插入記錄比中間記錄小 if (temp<source[mid] ) { // 插入點在低半?yún)^(qū) high = mid - 1; } else { // 插入點在高半?yún)^(qū) low = mid + 1; } } //將前面所有大于當前待插入記錄的記錄后移 for (j = i - 1; j >=low; j--) { source[j + 1] = source[j]; } //將待插入記錄回填到正確位置. source[low] = temp; System.out.print("第" + i + "趟排序:"); printArray(source); } } private static void printArray(int[] source) { for (int i = 0; i < source.length; i++) { System.out.print("\t" + source[i]); } System.out.println(); } public static void main(String[] args) { int source[] = new int[] { 12, 15, 9, 14, 4, 18, 23, 6 }; System.out.print("初始關鍵字:"); printArray(source); System.out.println(""); binarySort(source); System.out.print("\n\n排序后結果:"); printArray(source); } }

總結

以上是生活随笔為你收集整理的Java 二分排序法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。