Brief introduction
First of all, we have to briefly introduce the algorithm for fast sorting.
The fast sort (Quicksort), also known as dividing-exchange sorting (Partition-exchange sort), is a sort algorithm that was first proposed by Donny Holl. In average, sort n items to be 0 (n log n) times compared. In the worst-case scenario, 0 (N2) comparisons are required, but this is not a common situation. In fact, fast sorting is typically faster than the other 0 (n log n) algorithms because its internal loops (inner Loop) can be implemented efficiently on most architectures.
Fast sequencing is also known as one of the greatest algorithms of the 21st century. NO PIC SAY WHAT?
Each (unordered) split traversal sets the
first element to the pivot point
storage index = Pivot Point index +1
traversal from the i= axis index +1 to the right index
if the element [i] < element [Pivot Point] is
exchanged (I, storage index); Storage Index + +
Exchange (pivot point, storage index-1)
The idea is to choose an element that will be smaller than his left side, bigger than his to the right, and recursively finish all the unfinished arrays to accomplish the final goal.
Java implementation
public static void Main (string[] args) {int[] test = {6, 9, 28, 13, 31, 26, 1, 16, 7, 22, 49, 46,45,46};
Quicksort (test,0);
for (int i = 0; i < test.length i++) {System.out.print (Test[i] + "T");
}/** * each (unordered) split traversal * Sets the first element to Pivot * Storage index = Pivot Point Index +1 * Traversal from the i= Pivot Point index +1 to the right index * if element [i] < element [Pivot Point] * Exchange (I, storage index);
Storage Index + + * Exchange (pivot point, storage Index-1) * @param arr * * private static void Quicksort (int[] arr,int l) { if (l >= arr.length) return;//recursive exit int j = l + 1;//l as pivot point J as storage exponent for (int i = l; I < arr.length i
+ +) {if (J >= Arr.length) break;//Transboundary situation if (Arr[i] < arr[j]) {swap (arr, I, j);
} j + +;
if (j <= arr.length) swap (arr, l, j-1);
Quicksort (arr, ++l);
/** * Exchange of two elements in an array * @param arr * @param A * @param b * * private static void Swap (int[] Arr,int a,int b) {int temp = Arr[a];
Arr[a] = arr[b];
ARR[B] = temp; }
Output
1 6 7 9 13 16 22 26 28 31 45 46 46 49 Graphic Algorithm Directory
"Graphic algorithm" sorting algorithm--bubble sort, select sort
"Graphic algorithm" sorting algorithm--insert Sort
"Graphic algorithm" sorting algorithm--merging sort
"Graphic algorithm" sorting algorithm--fast sorting
"Graphic algorithm" Java GC algorithm
"Graphic algorithm" sorting algorithm--Heap sorting
"Graphic algorithm" and lookup set--Joint search algorithm
Gif Power by Https://visualgo.net