Java-preliminary Understanding-fifth-arrays-common operations-sorting performance issues

Source: Internet
Author: User

One.

Here the previous selection of the sorting operation has been deepened, the selection of the previous discussion is to compare the data on the 0-point mark and the back corner of the data from one after the other, and constantly change the position of the data, until the 0-point mark on the data is the smallest value in the entire array. Because of the number of exchanges, now raises a question, can be directly to the 0-point data and the minimum data for the exchange (if you know the minimum data of the angle mark is how much).

In the previous example, the selection of the sorting, three times to compare the exchange data, so that the data on the corner label 0 is the smallest. Now it's time to change the idea to solve the same problem.

The specific operation is: Define two variables first, why define two variables? A variable record is used to compare the elements of NUM, a variable that records the corner label value.

Think: by video, here is a place where two new variables are opened for recording and then manipulated on the two variables, and the array is not manipulated during the comparison. After all comparisons, two variables record the minimum and minimum values of the corner mark. Finally, the data of the 0-point data in the array and the 4-point data are exchanged directly. This idea compared to the previous problem-solving, carried out a pre-bedding. In fact, I think that the process of thinking, the operation is also quite a lot. The number of comparison records has been increased, and the number of exchanges has been reduced. The two variables are stored in the stack memory.

Java-preliminary Understanding-fifth-arrays-common operations-sorting performance issues

Related Article

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.