Summary of various common sorting algorithms in Java

First of all, there is sorting in Java

Note: (1) sort () in the arrays class uses the "tuned quick sort method"; (2) For example, for arrays of base data types such as int [], double [], char [], the arrays class only provides the default ascending arrangement, but does not provide the corresponding descending arrangement method. (3) To sort arrays of basic types in descending order, you need to convert these arrays into corresponding encapsulated class arrays, such as integer [], double [], character [], and sort these class arrays. (in fact, it's better to sort in ascending order first, and change to general order).

Step01: bubble sort

Principle: compare two adjacent elements and exchange the element with large value to one end.

Idea: compare the two adjacent numbers in turn, put the decimal in the front and the large number in the back. That is, in the first trip: first compare the first and second numbers, put the decimal before and the large number after. Then compare the second number and the third number, put the decimal before and after the large number, and continue until the last two numbers are compared, put the decimal before and after the large number.

Repeat the first step until all sorting is completed.

To view the specific implementation process:

Step02: select sort

Principle: select the smallest element from the records to be sorted in each trip and put it at one end.

Idea: for the first time, select the smallest number from the records and put it at one end. For the second time, select the smallest number from the remaining records and put it at the second place

Go down one by one until all sorting is completed.

View the specific execution process

Step03: insert sort directly

Direct insertion sorting is to insert unordered data into the appropriate position of the ordered sequence.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>