Algorithm analysis and improvement of bubbling sorting

xiaoxiao2021-03-06  75

The basic idea of ​​switching sort is: Two two two-two keywords to be sorted, and found that the two recorded sequences are exchanged, until there is no reagent record. The main sorting method of application exchange sorting basic ideas is: bubble sorting and rapid sorting. Bubbling Sort 1, the sorting method will be sorted vertically, each record R [i] is considered to be a bubble of R [i] .Key by weight. According to the principle of light bubbles, it cannot be scanned from the bottom, from the bottom to the array R: Anyone who scans the violation of this principles will make it "floating". So repeated, until the last two bubbles are in the light, the heavy people are below. (1) The initial R [1..N] is an unordered area. (2) The first scan compares the weight of the two bubbles from the bottom of the unordered area. If the light is discovered, the weight is on, then exchange the position of the two. That is, compared (R [N], R [N-1]), (R [N-1], R [N-2]), ..., (R [2], R [1]); for each pair Bubble (R [J 1], R [J]), if R [J 1] .Key

(2) The specific algorithm void bubblesort (SEQLIST R) {//r (L..N) is the file to be sorted, using the downward-down scan, to use the bubbles of the I, J; Boolean Exchange; // Sign for for (i = 1; i = i; j--) // Scan IF from the current sequencing area R [i..n] (R [J 1] .Key

转载请注明原文地址:https://www.9cbs.com/read-106982.html

New Post(0)