One dimensional array arrangement The problem of the bubble method

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

    First of all, because this array only has 10 data, and the subscript starts from 0 and ends at i=9.

    The comparison has been completed, because there is no data behind array[9], there is no need to compare, and if there is a comparison, there will be 10 and array[10] later, which is not right, syntax error.

    2.It is defined as j=i+1 because you don't have to compare with yourself, every time you compare, the current data has to be compared with the next data, for example, the current array[3] has to be compared with the next one, that is, array[4], and you don't have to compare with yourself. j<10 is the same as above, and compared to the number with the subscript 9.

    It's because it's used to exchange data, and it's because it takes two loops, and if it's defined as a[i] a[i+1], and only one time the adjacent data is compared, and it's done only once, then the largest number is just left behind.

    There is no better, this is the essence of the bubble method.

    Read it carefully, this is the most basic kung fu of the C language, if you master it, you will have a deeper understanding of programming.

  2. Anonymous users2024-02-06

    ;i<9;i++)

    Actually, as long as you compare 9 times, because the last number doesn't need to be compared, it's already arranged.

    For example: Now the right 2 numbers do you say to compare twice or once.

    Obviously, once is fine.

    j<10;j++) because the time of the comparison is from the next of the number you want to compare, 3No, because if it's a[i] a[i+1], it's inside the loop.

    will change, which will affect the next cycle. Actually, if you say a[i] a[i+1], then it will only loop once.

    You see if your program is like this.

  3. Anonymous users2024-02-05

    2 cycles. int a[10],x,y,j;

    for(x=0;x<10;x++) is the subject of comparison (a);

    for(y=x+1;y<10;y++) This cycle is compared to b with a;

    if(a[x]a[x]=a[y];Swap them back and continue to take him and the next one than a[y]=j;

    To put it simply, let the 10 numbers be compared separately. 1:2 1:3 1:4 1:5...

  4. Anonymous users2024-02-04

    1. Open Visual Studio and create a new Win32 program.

    2. In the open C language file, import the space, and then prepare a main function.

    3. Next, prepare an array of integers that need to be bubbled and sorted. As you can see in the figure below, the order of the numbers in the array is abnormal.

    4. Next, prepare the variables, and the prepared variables are used to sort the interaction data.

    5. Then we prepare two for loop arrays, we need to pay attention to the outer loop and the inner loop.

  5. Anonymous users2024-02-03

    #include""

    void main()

    int i,j,k,s;

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

    for(j=0;j<5;j++)

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

    printf("");

    This is coming. Put no line at the source.

    Arrange with the bubbling method, I.

    In writing a collective order of the entire two-dimensional array.

  6. Anonymous users2024-02-02

    #include

    int main()

    int i,j;

    int b[4*5];

    int k=0;

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

    for(i=0;i<4*5-1;i++)for(j=i+1;j<4*5;j++)if(b[i] is easier (can paste and copy, and can also be Chinese), and nothing else has changed in programming.

  7. Anonymous users2024-02-01

    Dear, glad to answer for you, to call the method of bubble sorting; You need to convert the collection to an array first, and then bubble sort by calling the array's methods. 1.Convert the set to an array, use the method of converting the set to an array, and convert the set into an array that needs to be sorted, which can be achieved by the toarray() method, 2

    Call the bubble sort method, declare a bubble sort method, and pass the converted array as an argument to the method. In this way, you can convert the data in the collection into an array and sort it using the bubble drain method. <>

  8. Anonymous users2024-01-31

    The second for loop (internal for loop) is wrong, the reason is not explained, too troublesome.

Related questions
20 answers2024-04-13

In fact, if you have read "C Expert Programming", it is very simple, and this problem has been carefully described above. It's stored in memory as shown in the figure. n[0][5] is actually *(*n+0)+5), which is the sixth cell. >>>More

12 answers2024-04-13

One-dimensional arrays hold the same values, but in the case of matrices, determinants. >>>More

7 answers2024-04-13

1 Maximum number of subscript elements - 1

2 Precautions for use: >>>More

10 answers2024-04-13

Combination + permutation problem People are divided into 3 groups, and there must be a group of two people, that is, 4 choose 2, c (2 groups go to 3 houses, it is a permutation problem, that is, p(3 >>>More

5 answers2024-04-13

1.Step 1: Set the shutter speed to the sensitivity number, for example, ISO 50 set the shutter speed to 1 60, ISO 100 to set about 1 125, in short, make the shutter speed as close to the reciprocal of sensitivity as possible. >>>More