bubblesort.java

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

JAVA
44
字号

/**
 * 
 * @author Harikrushna V
 */

public class BubbleSort {

	public static void select(double[] a) {
		int min;
		double temp;
		for (int i = 0; i < a.length; i++) {
			min = i;
			for (int j = i + 1; j < a.length; j++) {
				if (a[j] > a[min]) {
					min = j;
				}
				temp = a[i];
				a[i] = a[min];
				a[min] = temp;
			}
		}
	}

	public static void main(String[] args) {
		for (int N = 100; N <= 100000; 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();
			select(a);
			stop = System.currentTimeMillis();
			elapsed = (stop - start);
			// print the time
			System.out.println("Bubble:   " + elapsed + " seconds");
		}
	}
}

⌨️ 快捷键说明

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