Quick sorting is a sort algorithm. It is widely regarded as the optimal sorting algorithm to solve general problems. Like insert sorting, quick sorting is also a type of comparative sorting without additional storage space. Quick sorting is a good choice when processing medium to large data sets.
Fast sorting is a Sort Algorithm, so we can divide the sorting into three steps using the method of divide and conquer.
1. Split: Set a split value to divide the data into two parts.
2. Governance: The quick sorting method is used recursively.
3. Merge: sort the parts until they are completed.
The implementation code is as follows:
Import Java. util. random;/*** fast sorting {points, governance, and combination} * @ author Kevin Luan **/public class quicksort {public static void main (string [] ARGs) {int Total = 5; quicksort = new quicksort (); While (total> 0) {INTEGER arr [] = randomarray (1000000); long start = system. currenttimemillis (); quicksort. sort (ARR); system. out. println ("use time:" + (system. currenttimemillis ()-Start); quicksort. check (ARR); Total -- ;}} public void sort (integer [] ARR) {mergesort (ARR, 0, arr. length-1);} private void mergesort (integer arr [], int low, int high) {int A = low; int B = high; int middle; middle = getmiddle (ARR, low, high); While (low
The result of sorting 1 million random numbers is as follows (unit: milliseconds ):
Use Time: 249
Use Time: 205
Use Time: 245
Use Time: 220
Use Time: 203