zoukankan      html  css  js  c++  java
  • 七大基本排序算法之选择排序

    import java.io.IOException;
    import Input.InputString;
     
    /**
     * 选择排序
     * @author xiaomi
     * 2012.3.29
     */
    public class SelectSort {
        public static void main(String[] args) throws IOException{
            String s = InputString.getString();
            String[] str = s.split(" ");
            int[] a = new int[str.length];
            for(int i = 0;i < str.length;i++){
                a[i] = Integer.parseInt(str[i]);
            }
            selectSort(a);
            for(int i = 0;i < a.length;i++){
                System.out.print(a[i]+" ");
            }
        }
         
        public static void selectSort(int[] a){
            for(int i = 0;i < a.length;i++){
                int pos = i;
                for(int j = i;j < a.length;j++){
                    if(a[pos]>a[j]){
                        pos = j;
                    }
                }
                int temp = a[i];
                a[i] = a[pos];
                a[pos] = temp;
            }
        }
    }
  • 相关阅读:
    反射:框架设计的灵魂
    Junit测试
    XML笔记
    map 的用法
    opencv总结1
    光源
    镜面反射
    openGL纹理对象
    GPU入门
    动态规划1
  • 原文地址:https://www.cnblogs.com/williamxiao/p/3499948.html
Copyright © 2011-2022 走看看