Improvement of An Ascending Algorithm by Using Break Statement
Weida Qin, Yinhu Wei · 2022
Ascending algorithm enjoys important applications in fields such as automatic control, artificial intelligence. As an important ascending algorithm, the simple selection sorting method (ascending algorithm) aims to arrange a group of known disordered data in ascending order. Essentially, the simple selection sorting algorithm is comparison, subscript assignment and data exchange. By analyzing two different ascending algorithms which only use the main function for simple selection sorting and call function for simple selection sorting, it is found that ascending algorithm actually uses a double loop, with the outer loop controlling the number of ascending trips, and the inner loop controlling the number of comparison, assignment and data exchange. If no value is assigned in a certain inner loop, it indicates that the data has been ascended in order. In this study, while loop statement is used to replace the outer loop, and break statement is used to control the number of comparisons used in the ascending order. The improved algorithm uses fewer comparisons in the ascending order. Numerical experiments prove that the improved algorithm is effective, which not only supports the ascending order, but also effectively reduces the number of comparisons used in the ascending order, thus saving time.