Home > Common Problem > What is bubble sort algorithm

What is bubble sort algorithm

王林
Release: 2020-05-13 13:18:02
Original
6021 people have browsed it

What is bubble sort algorithm

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 come over. 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 principle of bubble sort algorithm:

Compare adjacent elements. If the first one is bigger than the second one, swap them both.

Do the same for each pair of adjacent elements, starting with the first pair and ending with the last pair. At this point, the last element should be the largest number.

Repeat the above steps for all elements except the last one.

Continue to repeat the above steps for fewer and fewer elements each time until there are no pairs of numbers to compare.

The above is the detailed content of What is bubble sort algorithm. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template