Sorting Algorithm Algorithms - sorting and selecting optimization

package com.ebiz.sort;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author YHj
 * @create 2019-07-28 20:58
 * 选择排序
 */
public class Choose {

    public static void main(String[] args) {
        int[] arr = new int[80000];
        for (int i = 0; i < 80000; i++) {
            arr[i] = (int) (Math.random() * 800000);
        }



        String s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        System.out.println("排序前 = " + s);

        getResult(arr);


        String l = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        System.out.println("排序后 = " + l);

    }



    public static void getResult(int[] arr) {
        for (int i = 0; i < arr.length-1; i++) {
            int min=arr[i]; //假设为最小值
            int minIdex=i;  // minimum index 
            for ( int J = I +. 1; J <arr.length; J ++ ) {
                 IF (min> ARR [J]) {
                     // find the position of the minimum and the minimum value 
                    min = ARR [J] ; 
                    minIdex = J; 
                } 
            } 
            // if the start position is not a non-optimized exchange 
            IF (minIdex =! I) { 
                ARR [minIdex] = ARR [I]; 
                ARR [I] = min; 
            } 
        } 
    } 



}

To be perfect ...

Guess you like

Origin www.cnblogs.com/jiushixihuandaqingtian/p/11299207.html