📄 bubblesort.java
字号:
/**
*
* @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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -