How to sort C++ Bubble and its Optimization algorithm
In this issue, the editor will bring you about how to sort C++ bubbles and its optimization algorithm. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.
Bubble sorting and its optimization algorithm steps
1. Compare adjacent elements. If the first is bigger than the second, exchange the two of them.
two。 Do the same for each pair of adjacent elements, from the first pair to the last pair. After this step is done, the last element will be the maximum number.
3. Repeat the above steps for all elements except the last one.
4. Continue to repeat the above steps for fewer and fewer elements each time, until there are no pairs of numbers to compare.
All programs / / in order to randomly generate integers between the intervals [mdjinn], the formula rand ()% (n-m+1) + m can be used. # includeusing namespace std;#define N 20int main () {int arry [N] = {0}; for (int item0