zoukankan      html  css  js  c++  java
  • classic problem: select sortjava

    /* javac SelectSort.java
     * java SelectSort 5 3 4 2 1 9 8 7 6
     *
     * */
    public class SelectSort {

        /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
       
            int arr[] = new int[args.length];
           
            for (int i=0; i<args.length; i++) {
                arr[i] = Integer.parseInt(args[i]);
                System.out.print(arr[i] + " ");
            }
            System.out.println();
           
            if (arr.length > 0) {
                selectSort(arr);
            }
           
            for (int i=0; i<arr.length; i++) {
                System.out.print(arr[i] + " ");
            }
        }
       
        public static void selectSort(int parr[]) {
            int k;
            int node;
           
            for (int i=0; i<parr.length; i++) {
                k = i;
                for (int j=k+1; j<parr.length; j++) {
                    if (parr[j] < parr[k]) {
                        k = j;
                    }
                }
               
                if (i != k) {
                    node = parr[i];
                    parr[i] = parr[k];
                    parr[k] = node;
                }
            }
        }   
    }

  • 相关阅读:
    Centos7下搭建SVN
    Ubuntu设置telnet 远程登录(root权限)
    E: 无法打开锁文件 /var/lib/dpkg/lock-frontend
    使用ICMP搭建隧道(PingTunnel)
    Centos7安装Redis
    idea 激活方法
    Chrome 浏览器安装 ChroPath 插件
    jmeter引入外部jar包的方法
    maven安装
    eclipse集成 json editor plugin插件
  • 原文地址:https://www.cnblogs.com/tiechui/p/1898662.html
Copyright © 2011-2022 走看看