phpstorm漢化後亂碼 漢字成方框問題
阿新 • • 發佈:2020-10-22
核心思想找一個軸點元素,備份軸點元素,先從右往左找,end--操作。一旦不滿足大小條件,則將右側的數值放置到開始位置,然後開始位置進行++,向右側找進行迴圈往復
public static void main(String[] args) { int ary[] = {6, 8, 8, 6, 2, 5, 9, 3, 7}; quickSort(ary); System.out.println(JSON.toJSONString(ary)); } private static void quickSort(int[] ary) { quickSort(ary,0, ary.length - 1); } private static void quickSort(int[] ary, int begin, int end) { if (end - begin < 2) return; int mid = getMid(ary, begin, end); quickSort(ary, begin, mid); quickSort(ary, mid + 1, end); } private static int getMid(int[] ary, intbegin, int end) { int tmp = ary[begin]; for (; begin < end; ) { for (; begin < end; ) { //從右往左檢查 if (tmp < ary[end]) { end--; } else {//大於等於 ary[begin++] = ary[end];break; } } for (; begin < end; ) { //從左往右檢查 if (tmp > ary[begin]) { begin++; } else { ary[end--] = ary[begin]; break; } } } ary[begin] = tmp; return begin; }