Selection and sorting of algorithms

Source: Internet
Author: User

Select a sort basic idea: Select a minimum element from all elements a[i] in a[0] (that is, let the smallest element a[i] and a[0] exchange), as the first round, the second round is from the beginning of the a[1] to the final elements of the selection of a minimum element, placed in the a[1]; In turn. n the number of (n-1) wheels to be carried out. The number of comparisons is as much as the bubbling method, but only one exchange in each round is less than that of bubbling, which is efficient compared to the bubbling method.

/** *  */package com.zimo.algorithm;/** * @author Sub-ink * * 2015-3-4 PM 10:51:32 */public class Selectsort {/** * @param arg s */public static void Main (string[] args) {int[] data={25,15,42,16,12,36};selectsort (data); for (int i = 0; i < Data.le Ngth; i++) {System.out.println (data[i]);}} /** * Select sort * @param data */private static void Selectsort (int[] data) {int temp;int min;for (int i = 0; i < data.length ; i++) {min = i;for (int j = i+1; J < Data.length; J + +) {if (Data[min] > Data[j]) {min=j;}} temp = Data[i];d ata[i] = Data[min];d ata[min] = temp;}}}


Selection and sorting of algorithms

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.