Bubbling Sort vb, C language bubbling sort method

Updated on technology 2024-04-11
8 answers
  1. Anonymous users2024-02-07

    When bubbling sorted.

    for j = 0 to n - 2

    for i = 0 to n - 2 - j should be. for j = 0 to n - 1for i = j+1 to n

  2. Anonymous users2024-02-06

    #include

    Link the standard header file.

    #definen5

    Define the constant n and assign a value of 5

    voidmain()

    The main function entry.

    End of cycle. for(i=0;i starts the outer for loop, from i 0, each time by 1, until i = 4 from then on the exchange of the size variables, so that the large value is put forward} to end the inner loop.

    The outer and inner layers of the knot circulate to complete the sorting.

    printf("The last order is:");On the screen explicitly "Sort last as:" and wrap lines.

    for(i=0;i is similar to the starting for loop.

    End the loop output.

    printf("");

    The output wraps to the screen, and you can't see any effect, you can delete it} to end the main() function.

  3. Anonymous users2024-02-05

    sort1(t[5], 5);

    change to sort1(t,5);

    #include

    void sort1(int t, int x)}int main()

    It's a small to large row.

  4. Anonymous users2024-02-04

    First of all, you don't have inputs and outputs at all.

    Second, the boundary condition of the bubbling loop is wrong, when i==n-2, j>=i+1, j can get n-1, so that a[j+1] in the following judgment statement can be taken a[n], out of bounds.

    #include

    #define n 10

    int main ()

    printf("output the sorted numbers:");

    for (i=0; i

  5. Anonymous users2024-02-03

    The following is an example of four numbers for easy understanding;

    #include

    main()

    Define an array, which is a combination of numbers to be sorted this time; Note that there are 4 numbers in the array here, so theoretically: a[4]=;

    Initial test i=1;and determine whether i is less than or equal to 3; If the conditions are met, then enter the for loop; (4 numbers, 3 rounds of comparison are required for pairwise comparison, and i represents the number of rounds; i needs to go through three rounds of assignment of 1,2,3; i=4 will jump out of the for loop).

    for(i=1; i<=3; i++)for(i=0; i<4; i++)

    *The result of the run is as follows:

    The first number is: 3

    The second digit is: 6

    The third digit is: 10

    The fourth digit is: 30*

  6. Anonymous users2024-02-02

    Bubbling sorting, in each comparison, if you find that the order of the two adjacent numbers is wrong, the two numbers will be reversed immediately.

    If you select Sort, you will not be swapped during the comparison process (in the inner loop), but the minimum (large) number of subscripts will be recorded first, and then reversed after a scan is completed. So it's going to be a little more efficient than bubbling.

    But bubbling sort is a "stable" sort. That is to say, several students with the same total score, who are ranked first, will not change their positions with each other after sorting.

    Whereas, the selection sort is "unstable" sorting. That is to say, several students with the same total score were originally ranked relatively first before the sorting, and may change to the back after the sorting.

  7. Anonymous users2024-02-01

    Bubbling sort is the easiest sorting method and is easy to understand. Although it has more calculation steps and is not the fastest, it is the most basic and must be mastered by beginners.

    The principle of bubble sorting is: from left to right, adjacent elements are compared. Each round of comparison finds the largest or smallest one in the sequence. This number will pop up from the far right of the sequence.

    For example, after the first round of comparison, the largest number in all numbers will float to the far right; After the second round of comparison, the second highest number of all numbers will float to the second-to-last position......In this way, round by round, the comparison is carried out, and finally the order is achieved from small to large.

    For example, sort the following sequence from smallest to largest:

    First round: 1) 90 and 21 vs. 90>21, then they swap places:

    2) 90 and 132 ratio, 90 < 132, then do not swap places.

    3) 132 and 58 ratio, 132 > 58, then they swap positions:

    4) 132 and 34 ratio, 132>34, then they swap positions:

    At this point, the first round is over. The result of the first round is to find the largest number in the sequence and float to the far right.

    When comparing, the nth comparison in each round is a comparison of the nth element and the n+1st element in the new sequence (assuming n starts at 1).

    Second round: 1) 21 and 90 ratio, 21<90, no need to swap places.

    2) 90 and 58 ratio, 90 > 58, then they swap positions:

    3) 90 and 34 ratio, 90>34, then they swap places:

    At this point, the second round of comparison is over. The result of the second round is to find the second largest number in the sequence and float to the second position on the far right.

    Third round: 1) 21 and 58 ratio, 21 > 58, then they swap places:

    2) 21 and 34 ratio, 21<34, then do not switch places.

    At this point, the third round is over. The result of the third round is to find the third largest number in the sequence and float to the third position on the far right.

    Fourth round: 1) 58 and 21 vs. 58<21, no place swapping.

    At this point, the entire sequence is sorted. The sequence from small to large is "58 21 34 90 132". From this example, it can also be concluded that if there are n data, then only n 1 rounds need to be compared.

    And with the exception of the first round, you don't have to compare all of them. Because after the comparison of the previous rounds, the rounds that have been compared have found the largest number in the round and floated to the right, so the number on the right does not need to be compared.

  8. Anonymous users2024-01-31

    The so-called bubble sorting method is an algorithm that sorts a group of numbers from large to small or from small to large.

    1. The specific method is to exchange adjacent values in pairs. Starting with the first number, if the order of the two adjacent numbers is different from what we expect, the positions of the two numbers are swapped (reversed); If it matches our expectations, there is no need to exchange. This process is repeated until there are no values to be exchanged at the end, and the sorting is complete.

    The details are shown in the figure below:

    2. In order to achieve the effect, we must first define a set of numbers to be sorted and each variable. The specific situation is shown in the figure below:

    5. According to the above procedure, when the fifth trip (i=5) bubbles, the computer not only compares and sorts "1,5,6,4" in pairs, but also compares and sorts "7,8,9,13" in pairs, and "7,8,9,13" has been sorted in the fourth blistering trip, so it is very redundant to compare. The diagram is as follows:

Related questions
18 answers2024-04-11

Bubbling sort is the least efficient. Juvenile! You can quickly sort it, and you will understand it in minutes.

8 answers2024-04-11

The central idea of bubbling ordering is to start at the head of the unordered sequence, compare them in pairs, swap positions according to size, and finally swap the largest (small) data element to the end of the unordered queue, thus becoming part of the ordered sequence; Continue the process next time until all the data elements are ordered. The core of the algorithm is to select the largest (smallest) data element in the remaining disordered sequence and put it at the end of the queue by comparing the positions in pairs at a time. >>>More

23 answers2024-04-11

For example: QQ

Stealth, it's called diving, I don't want people who don't want to know that they are surfing the Internet! >>>More

28 answers2024-04-11

Go to the 4S shop to check it, this will have a lot to do with the condition of your car, and the situation of new cars and old cars will not be the same. If it is broken suddenly, the possible problems will be more complicated, such as the fan does not rotate and does not dissipate heat, the water pump is broken and does not rotate and does not circulate, which will lead to high engine pressure, and water leakage and lack of water may also lead to too high boiling pressure, which can easily lead to high pressure in the water system.

15 answers2024-04-11

On the other hand, there are many air vents on the eggshell that are invisible to the naked eye, (otherwise how to discharge the gas produced by metabolism inside), and when cooking, the gas expands by heating and will escape from the holes, and that's it. And you should have steamed eggs, when steaming, the eggs are easy to break because the gas inside expands too fast, and the eggshell can't withstand the tension, that's it, if there are other small problems in life, leave me a message Oh, I'll try my best to help you answer Hehe.