Traditional Culture Encyclopedia - Weather inquiry - The bubbling method in C language has never been understood. Please make it simple and detailed according to the chart. That's right. Ten points.
The bubbling method in C language has never been understood. Please make it simple and detailed according to the chart. That's right. Ten points.
The outer loop corresponds to the loop of I in the algorithm you gave, from 1 to n- 1, and the loop is n- 1 times. For each value of I, there will be a smallest element floating to the position of i- 1, and the elements before i- 1 have been sorted from small to large.
For example, when i= 1, pj points to the last element 1, and then judge the size relationship between the element before pj and the element pointed by pj. If pj- 1 points to an element greater than that pointed by pj, swap two elements, and then pj points to the position of the previous element until pj & gtP+i- 1, where p points to the first address of the array. When i= 1, p+i- 1 is p+0, pointing to the first address of the array. At this point i= 1, so the smallest element in the array will float to the first I-65438+ at the end of this period. Generally speaking, the value of each outer loop I is the number of sequences arranged in front of the array from small to large+1. For example, when i=3, it means that while the outer loop is going on, two elements have been arranged in order, and at the end of the loop, three elements have been arranged in order, from small to large, at the first place in the array.
- Previous article:What are the places suitable for children to play in Shenyang?
- Next article:What are the rainstorm warning signals?
- Related articles
- Coat recommends spring temperament.
- Which weather software is accurate?
- Can Lingshui go online in January?
- One-month weather forecast in Hechuan
- Copywriting suitable for sending friends on a hot day
- Cooking method of health porridge in summer
- Why is there' white smoke' when you exhale in winter, but there is no white air when you turn on the air conditioner in summer? (Kneeling for a detailed answer)
- Cold cough
- 5. 1 self-help tour of Danxia Mountain in Nanhua Temple, Shaoguan
- What should I do if my mobile phone is hot?