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;
                }
            }
        }   
    }

  • 相关阅读:
    When to Partition a Table and an Index
    Hello, world
    提交
    SubmitOncePage:解决刷新页面造成的数据重复提交问题
    压缩ASP.NET中的ViewState
    asp.net千奇百怪的日历
    ICallbackEventHandler实现
    xml數據
    CrystalReports
    [转]Microsoft Visual Studio 2005中使用水晶报表
  • 原文地址:https://www.cnblogs.com/tiechui/p/1898662.html
Copyright © 2011-2022 走看看