Remember that the array order starts from 0!!!
Remember that the array order starts from 0!!!
Remember that the array order starts from 0!!!
Important thing to say three times!
------------------------------------------------------------raw data
13, 24, 17, 45, 12, 33, 54, 46, 53, 68, 67, 44, 91
13, 17, 24, 12, 33, 45, 46, 53, 54, 67, 44, 68, 91
13, 17, 12, 24, 33, 45, 46, 53, 54, 44, 67, 68, 91
13, 12, 17, 24, 33, 45, 46, 53, 44, 54, 67, 68, 91
12, 13, 17, 24, 33, 45, 46, 44, 53, 54, 67, 68, 91
12, 13, 17, 24, 33, 45, 44, 46, 53, 54, 67, 68, 91
12, 13, 17, 24, 33, 44, 45, 46, 53, 54, 67, 68, 91
After reading the class example, I also wrote an array, practice, and found that the number of two for the loop of the outer layer of the loop is not related to the length of the array, the above array length is 13, but the Loop 7 times to complete the sort, but the program is looped 12 times, The following 5 times is an empty loop, the class example array length is 8, the Loop 6 times to complete the sorting, just to cooperate with the control of the inner layer of the loop, so the back of the empty loop is necessary, the number of visible outer loop is actually related to the arrangement of the original data.
Do not know this understanding is right or wrong, I hope that teachers and students to guide.
There's a picture of the truth
int[] we =New int[]{13, 24, 54, 17, 45, 12, 33, 68, 46, 53, 91, 67, 44}; for(intq:we) {System.out.print (q+ " "); } for(intb = 1; b < we.length; b++) { for(intA = 0; A < We.length-b; a++) { if(We[a] > we[a + 1]) { intn = we[a + 1]; We[a+ 1] =We[a]; We[a]=N; }}} System.out.println (); for(intq:we) {System.out.print (q+ " "); }
Two-dimensional array and bubble sort 2