Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the implementation method of Java sorting algorithm?

Shulou Source: shulou.com Published: 2022-06-02 19:18:09 09月17日 Update

This article mainly introduces "Java sorting algorithm implementation method is what", in daily operation, I believe many people in Java sorting algorithm implementation method is what the problem is there are doubts, small series consulted all kinds of information, sorted out simple and easy to use operation method, hope to answer "Java sorting algorithm implementation method is what" doubts helpful! Next, please follow the small series to learn together!

Bubble Sort:

(1) Principle:

Starting with the first data, compare it with the second data, and if the second data is smaller than the first data, swap the positions of the two data.

The pointer moves from the first data to the second data, the second data is compared with the third data, and if the third data is less than the second data, the positions of the two data are exchanged.

And so on, completing the first round of sorting. At the end of the first sorting round, the largest element is moved to the far right.

Follow the above procedure for the second round of sorting, placing the second largest in the penultimate position.

Repeat the above process, and reduce the number of comparisons once before finishing a round.

(2) Examples:

Data to be sorted: 7, 6, 9, 8, 5, 1

First round sorting process:

Pointer points to 7, 7 and 6 compare, 67, without swapping positions, the result is still: 6, 7, 9, 8, 5, 1 Pointer points to the third element 9, compare 9 and 8, 8

Tags: Sort element data pointer result algorithm loop point number threshold round order position selection right face vacancy method array procedure Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Information Shulou Technology OPPO Reno Docker