Two-dimensional array and bubble sort 2

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.