The fast sorting algorithm belongs to the sort of "exchange class", and its efficiency is mainly related to the symmetry of data distribution.
Sort Ascending:
/** * Quick Sort * ascending sort * * @Overridepublic <t extends comparable<? Super T>> Vo ID SORTBYASC (t[] data) {if (data = = NULL | | data.length <= 1) {return;} PARTITIONSORTBYASC (data, 0, data.length-1);} Private <t extends comparable<? Super t>> void Partitionsortbyasc (t[] data, int low, int.) {if (low >= high) {return;} /** uses two pointers start and end*/int start = Low;int end = high; T key = data[low];/** locates the key, then divides data into two parts, recursively */while (Start < end) {while (Start < end && Data[start], respectively. CompareTo (Key) < 0) {start + +;} if (Data[start].compareto (key) > 0) {T temp = Data[start];d Ata[start] = Data[end];d ata[end] = temp;} while (Start < end && Data[end].compareto (key) > 0) {end--;} if (Data[end].compareto (key) <= 0) {T temp = Data[end];d ata[end] = Data[start];d Ata[start] = temp;}} /** */if (Start > Low) PARTITIONSORTBYASC (data,low,start-1) on the left,/** (end < High) */if (data, End + 1, high);}
Sort Descending:
/** * Quick Sort * descending sort * * * @Overridepublic <t extends comparable<? Super t>> void Sortbydesc (t[] data) {PARTITIONSORTBYDESC (data, 0, data.length-1);} Private <t extends comparable<? Super t>> void Partitionsortbydesc (t[] data, int low, int.) {if (low >= high) {return;} /** uses two pointers start and end*/int start = Low;int end = high; T key = data[low];/** locates the key, then divides data into two parts, recursively */while (Start < end) {while (Start < end && Data[start], respectively. CompareTo (key) > 0) {start + +;} if (Data[start].compareto (key) <= 0) {T temp = Data[start];d Ata[start] = Data[end];d ata[end] = temp;} while (Start < end && Data[end].compareto (key) < 0) {end--;} if (Data[end].compareto (key) > 0) {T temp = Data[end];d ata[end] = Data[start];d Ata[start] = temp;}} /** */if (Start > Low) Partitionsortbydesc (data,low,start-1) on the left,/** (end < High) */if (data, End + 1, high);}
A sort algorithm of data structure Java implementation (4)--Fast sorting algorithm of Exchange class ordering