Simple implementation of Java bubble sorting
Algorithm description: for a given n records, compare two adjacent records successively from the first record. When the previous record is larger than the subsequent record, exchange the position. After a round of comparison and exchange, the largest record in the n records will be in the nth position; The first (n-1) records are then compared for the second round; the process is repeated until there is only one record to be compared.
Bubble sorting is very easy to understand. Take the sorting from small to large as an example. In each round of sorting, the maximum value in the unordered sequence is found and placed last.
Set the length of the array to N:
(1) Compare the two adjacent data before and after. If the previous data is greater than the subsequent data, exchange the two data.
(2) In this way, after traversing the 0th data to n-1 data of the array, the largest data will "sink" to the N-1 position of the array.
(3) N = n-1. If n is not 0, repeat the previous two steps, otherwise the sorting is completed.
The above is the basic idea of bubble sorting. According to this definition, you can write code quickly.