<> One , Advanced sort

<>【1】 Shell Sort
public class Shell Sort { public static void main(String[] args) { Integer[] arr =
{3, 1, 5, 2, 4, 4, 9, 8, 7}; Hill.sort(arr);
System.out.println(Arrays.toString(arr)); } } class Hill { public static void
sort(Integer[] t) { Integer temp; Integer h = 1; while (h < (t.length / 2)) { h
= h * 2 + 1; } while (h != 0) { for (int i = h; i < t.length; i++) { for (int j
= i; j >= h; j -= h) { if (t[j] < t[j - h]) { temp = t[j]; t[j] = t[j - h]; t[j
- h] = temp; } else { break; } } } h /= 2; } } }
<>【2】 Merge sort
public class Merge sort { public static void main(String[] args) { Integer[] arr =
{3, 1, 5, 2, 4, 4, 9, 8, 7}; Merge.sort(arr);
System.out.println(Arrays.toString(arr)); } } class Merge { private static
Integer[] buffer; static void sort(Integer[] t) { buffer = new
Integer[t.length]; split(t, 0, t.length - 1); } private static void
split(Integer[] integers, Integer startIndex, Integer stopIndex) { if
(startIndex == stopIndex) { return; } Integer midIndex = (stopIndex +
startIndex) / 2; split(integers, startIndex, midIndex); split(integers,
midIndex + 1, stopIndex); sortByMerge(integers, startIndex, midIndex,
stopIndex); } private static void sortByMerge(Integer[] integers, Integer l,
Integer m, Integer r) { Integer bufferIndex = l; Integer leftIndex = l; Integer
rightIndex = m + 1; while (leftIndex <= m && rightIndex <= r) { if
(integers[leftIndex] < integers[rightIndex]) { buffer[bufferIndex++] =
integers[leftIndex++]; } else { buffer[bufferIndex++] = integers[rightIndex++];
} } while (leftIndex <= m) { buffer[bufferIndex++] = integers[leftIndex++]; }
while (rightIndex <= r) { buffer[bufferIndex++] = integers[rightIndex++]; } if
(r + 1 - l >= 0) System.arraycopy(buffer, l, integers, l, r + 1 - l); } }
<>【3】 Quick sort
public class Quick sort { public static void main(String[] args) { Integer[] arr =
{3, 1, 5, 2, 4, 4, 9, 8, 7}; Quick.sort(arr, 0, arr.length - 1); //
Quick.partition(arr,1,arr.length - 1);
System.out.println(Arrays.toString(arr)); } } class Quick { public static void
sort(Integer[] arr, Integer leftIndex, Integer rightIndex) { if (leftIndex >=
rightIndex) { return; } Integer partitionIndex = partition(arr, leftIndex,
rightIndex); sort(arr, leftIndex, partitionIndex - 1); sort(arr, partitionIndex
+ 1, rightIndex); } static Integer left; static Integer right; static Integer
key; static Integer temp; public static Integer partition(Integer[] arr,
Integer l, Integer r) { left = l; right = r + 1; key = l; while (true) { while
(arr[key] < arr[--right]) { if (right <= left) { break; } } while (arr[key] >
arr[++left]) { if (right <= left) { break; } } if (left < right) { temp =
arr[left]; arr[left] = arr[right]; arr[right] = temp; } else { temp = arr[key];
arr[key] = arr[right]; arr[right] = temp; break; } } return right; } }

Technology
©2019-2020 Toolsou All rights reserved,
Error summary -myBatis plus paging use easyPOI Import Excel data In the problem of target detection “ recall Recall”,“ Accuracy Precision”vue use vue-clipboard2 Realize the function of copy link C In language switch sentence Wechat applet (uni-app)url Parameter transfer object hive compress &&hdfs Merge small files hive Summary of processing methods for a large number of small files use spring Of AntPathMatcher matching url route Linux Page replacement algorithm C Language implementation