排序算法有:
冒泡排序、插值排序、選擇排序、HASH排序、快速排序
冒泡排序:
public static void bubbleSort(int[] array) {
for (int i = 1; i < array.length; i++) {
for (int j = 0; j < i; j++) {
if (array[i] < array[j]) {
int temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
}
快速排序:
public class QuickSort {
public void quickSort(String[] strDate, int left, int right) {
String middle, tempDate;
int i, j;
i = left;
j = right;
middle = strDate[(i + j) / 2];
do {
while (strDate[i].compareTo(middle) < 0 && i < right)
i++; // 找出左邊比中間值大的數(shù)
while (strDate[j].compareTo(middle) > 0 && j > left)
j--; // 找出右邊比中間值小的數(shù)
if (i <= j) { // 將左邊大的數(shù)和右邊小的數(shù)進(jìn)行替換
tempDate = strDate[i];
strDate[i] = strDate[j];
strDate[j] = tempDate;
i++;
j--;
}
} while (i <= j); // 當(dāng)兩者交錯(cuò)時(shí)停止
if (i < right) {
quickSort(strDate, i, right);
}
if (j > left) {
quickSort(strDate, left, j);
}
}
public static void main(String[] args) {
String[] strVoid = new String[] { "11", "66", "22", "0", "55", "22", "0", "32" };
QuickSort sort = new QuickSort();
sort.quickSort(strVoid, 0, strVoid.length - 1);
for (int i = 0; i < strVoid.length; i++) {
System.out.println(strVoid[i] + " ");
}
}
}
遠(yuǎn)近互聯(lián)技術(shù)-劉 整理發(fā)布,希望能對(duì)同是技術(shù)的你有所幫助。
遠(yuǎn)近互聯(lián)專業(yè)提供網(wǎng)站建設(shè)、APP開發(fā)、網(wǎng)站優(yōu)化、外貿(mào)網(wǎng)站SEO、微信運(yùn)營的品牌整合營銷服務(wù),讓客戶通過網(wǎng)絡(luò)品牌建立與網(wǎng)絡(luò)傳播提高業(yè)績。






