The choice of Jave basis

Source: Internet
Author: User

Select sort (Selection sort)
    • Basic introduction

Select Sort:
The smallest (or largest) element is selected for each data element that has never been sorted, stored at the beginning of the sequence, and then the smallest (or largest) of the remaining unsorted elements is placed at the end of the sorted sequence until all the data elements to be sorted are exhausted.
Select Sort is an unstable sort method (for example, sequence [5, 5, 3] swaps the first [5] with [3] for the first time, causing the first 5 to move back to the second 5).

    • Algorithm introduction (subsequent additions)

    • Performance Introduction (Subsequent additions)

    • Introduction to Suboptimal (Follow-up supplement)

    • Code presentation (for example from small to large)

public class SelectSort {    public static void main(String[] args){        int[] arr = {1,22,32,2,5,75,46,37,23,99};        int[] arrSort = selectSort(arr);        for(int i = 0; i < arrSort.length; i++){            System.out.println(arr[i]);        }    }    //选择排序    public static int[] selectSort(int[] arr){        int minIndex = 0;        for(int i = 0; i < arr.length-1; i++){            minIndex = i;//用来动态记录较小数字的下标            for(int j = i+1; j < arr.length; j++){                if(arr[minIndex] > arr[j]){                    minIndex = j;                }            }            if(minIndex != i){                arr[minIndex] = arr[minIndex] + arr[i];                arr[i] = arr[minIndex] - arr[i];                arr[minIndex] = arr[minIndex] - arr[i];            }        }        return arr;    }}

The choice of Jave basis

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.