Home  >  Article  >  Is the basic idea of ​​bubble sorting to compare adjacent data items in a sequence?

Is the basic idea of ​​bubble sorting to compare adjacent data items in a sequence?

藏色散人
藏色散人Original
2020-05-12 09:38:075846browse

Is the basic idea of ​​bubble sorting to compare adjacent data items in a sequence?

Is the basic idea of ​​bubble sorting to compare adjacent data items in a sequence?

The basic idea of ​​bubble sorting is to compare adjacent data items in the sequence, exchange them if there is a reverse order, and repeat until they are in order.

Bubble Sort is a relatively simple sorting algorithm in the field of computer science.

It repeatedly visits the column of elements to be sorted, compares two adjacent elements in turn, and swaps them if the order (such as from large to small, first letter from Z to A) is wrong. The work of visiting elements is repeated until no adjacent elements need to be exchanged, which means that the element column has been sorted.

The name of this algorithm comes from the fact that smaller elements will slowly "float" to the top of the sequence through exchange (in ascending or descending order), just like the carbon dioxide bubbles in carbonated drinks will eventually float to the top. , hence the name "bubble sort".

The above is the detailed content of Is the basic idea of ​​bubble sorting to compare adjacent data items in a sequence?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn