The relationship between the number of bubble sort exchanges and the number of reversed pairs

relationship:

Suppose you want to sort the sequence from smallest to largest.

Bubble sorting exchanges every time it encounters adjacent a[i]>a[i+1]. Obviously, the two numbers exchanged each time must be reversed pairs.
Each exchange means reducing one reversed pair, then the total number of exchanges is the total number of reversed pairs of the sequence.


Guess you like

Origin blog.csdn.net/weixin_44178736/article/details/114847961