Is the same as all other languages. The fastest sort should be the most efficient.
public static void Bubblesort (int a[]) {
int len = a.length;
for (int i = 0; i < len-1; i++) {
for (int j = 0; J < len-1-I; j + +) {
if (A[j] > a[j + 1]) {
int temp = A[j];
A[J] = a[j + 1];
A[j + 1] = temp;
}
}
}
}
public static void Selectsort (int a[]) {
int temp = 0;
int len = a.length;
for (int i = 0; i < len-1; i++) {
int min = a[i];
int index = i;
for (int j = i + 1; j < Len; J + +) {
if (min > A[j]) {
min = A[j];
index = j;
}
}
temp = A[i];
A[i] = A[index];
A[index] = temp;
}
}
public static void Insertsort (int a[]) {
int len = a.length;
for (int i = 1; i < Len; i++) {
int temp = a[i];//value to be inserted
int index = i;//the position to be inserted
while (Index > 0 && a[index-1] > Temp) {
A[index] = a[index-1];//the position to be inserted to re-assign a larger value
index--;//Position move forward
}
A[index] = temp;
}
}
public static int partition (int a[], int. low, int height) {
int key = A[low];
while (Low < height) {
while (Low < height && A[height] >= key)
height--;
A[low] = A[height];
while (Low < height && A[low] <= key)
low++;
A[height] = A[low];
}
A[low] = key;
return low;
}
public static void QuickSort (int. a[], int low, int height) {
if (Low < height) {
int result = partition (A, low, height);
QuickSort (A, low, result-1);
QuickSort (A, result + 1, height);
}
}
Test results
------------------------------------------
Test Data 10000
Bubble Sort: 120ms
Select Sort: 32ms
Insertion Sort: 20ms
Quick sort: 7ms
------------------------------------------
Test data 100000
Bubble Sort: 13098ms
Select Sort: 2334ms
Insertion Sort: 1264ms
Quick sort: 23ms
The efficiency gap is very big AH!!!
Java sort, what sort of a high-efficiency method