Bubble sort is one of the simplest answers in exchange sequencing.
Sort Ascending:
/** * Bubble Sort * ascending sort * * * @Overridepublic <t extends comparable<? Super t>> void Sortbyasc (t[] data) {if (data = = NULL | | data.length <= 1) {return;} /** up to n-1 */for (int i = 0; i < data.length-1; i + +) {/** Sorts the current unordered interval, the range of J is in the Progressively shrinking */for (int j = 0; J < data.length -1-i; J + +) {if (Data[j].compareto (Data[j + 1]) > 0) {T temp = Data[j];d ata[j] = data[j + 1];d ata[j + 1] = temp;}}}}
Sort Descending:
/** * Bubble Sort * descending sort * * * @Overridepublic <t extends comparable<? Super t>> void Sortbydesc (t[] data) {if (data = = NULL | | data.length <= 1) {return;} /** up to n-1 */for (int i = 0; i < data.length; i + +) {/** Sorts the current unordered interval, the range of J is in the Progressively shrinking */for (int j = 0; J < data.length-1 I J + +) {if (Data[j].compareto (Data[j + 1]) < 0) {T temp = Data[j];d ata[j] = data[j + 1];d ata[j + 1] = temp;}}}}
The sorting algorithm of data structure Java implementation (3)--Bubble sorting algorithm