Traditional Culture Encyclopedia - Traditional virtues - Bubble sorting in c language
Bubble sorting in c language
Bubble sorting in C language is a basic exchange sorting, which is very simple. Bubble sorting in C language is to arrange the sorted record array vertically, and each record R is regarded as a bubble with a weight of R.key According to the principle that a light bubble cannot be below a heavy bubble, the sorting is to scan the array R from bottom to top. Every light bubble that violates this principle will be scanned, so it will float upwards. Repeat this process until the last two bubbles, the lighter one is at the top and the heavier one is at the bottom.
Bubble sorting in C language is suitable for dealing with small-scale data sets, in which the number of elements is relatively small. In this case, the performance of bubble sorting is acceptable and the implementation is simple. If the data set to be sorted is partially ordered, that is, only a few elements need to be sorted, and other elements are already ordered, then the performance of bubble sorting will be relatively good.
Advantages of bubble sorting in c language
1, easy to understand
The realization logic of bubble sorting is simple and easy to understand and realize. It only needs to use basic comparison and exchange operations to complete the sorting.
2. In-situ sorting
Bubble sorting is an in-situ sorting algorithm, which does not need extra space to store the sorting results. It only needs to compare and exchange elements on the original array.
3. Stability
Bubble sorting is a stable sorting algorithm, that is, the relative order of equal elements remains unchanged before and after sorting. Only when two adjacent elements are exchanged, their relative order will change.
4. Suitable for small-scale data.
Due to the low time complexity of bubble sorting, the performance of bubble sorting is acceptable in the case of small data scale. For small-scale data sets, bubble sorting may be faster than other complex sorting algorithms.
- Previous article:What are some Jewish traditions and customs related to books 4 articles
- Next article:Why is XP system always so prone to viruses?
- Related articles
- Four-character idioms related to animals
- China traditional color number hand-painted
- Why do rubies and sapphires need to be heated? What else is heated?
- Classification of strength of metallic materials
- What is the opening name of Henan Opera?
- Business development measures of insurance companies
- Do holidays include Saturday and Sunday?
- Tian Qinxin, director of Red Starting Point: What do you think of putting the study of party history on the stage?
- China traditional gift recommendation letter in English
- The company group building activities organization plan