selectionsort.java

来自「bubble sort quick sort selection sor」· Java 代码 · 共 45 行

JAVA
45
字号



public class SelectionSort {
    public static void bubble(double[] a) {
    	
    	double temp;
    	for(int i=0;i<a.length-1;i++)
        {
            for(int j=0;j<a.length-1-i;j++)
            {
                if(a[j] < a[j+1])
                {
                    temp=a[j];
                    a[j]=a[j+1];
                    a[j+1]=temp;
                }
            }
        }
    }

    public static void main(String[] args) {
        for(int N=100;N<=1000000;N*=10)
        {
	        long start;
	        long stop;
	        double elapsed;
	        double[] a = new double[N];
	        for (int i = 0; i < N; i++)
	                a[i] = i;
	        
	        // sort them
	        start = System.currentTimeMillis();
	        bubble(a);
	        stop = System.currentTimeMillis();
	        elapsed = (stop - start) ;
	        //print the time 
	        System.out.println("Selection:   " + elapsed + " seconds");
	    }
    }
}



⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?