Sort by sorting algorithm (JAVA)

Source: Internet
Author: User

[Java] public class SelectSort {/*** each trip selects the smallest (or largest) element from the data element to be sorted, and places it at the end of the sorted series, until all data elements to be sorted are arranged. * Select sorting: Simple selection sorting, Tree Selection sorting (tournament sorting), and heap sorting. This algorithm is simple selection sorting * time complexity is O (n ^ 2) * unstable sorting method * @ param nums array to be sorted * @ return output ordered array */public static void sort (int [] nums) {for (int I = 0; I <nums. length; I ++) {int minIndex = I; for (int j = I + 1; j <nums. length; j ++) {if (nums [minIndex]> nums [j]) {minIndex = j ;}} if (minIndex! = I) {int temp = nums [I]; nums [I] = nums [minIndex]; nums [minIndex] = temp ;}}}}

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.