有誰知道這是什麼樣的排序在java中?我不太確定我自己。插入?選擇?提前致謝!這是什麼樣的? - Java
public class sorting {
public static void main(String[] args)
{
String[] arr = {"Banana", "Apple", "Orange", "Fruit", "Watermelon", "Hello World"};
String tmp;
for (int i = 0;i < arr.length;i++)
{
tmp = arr[i];
for (int j = 0;j < arr.length;j++)
{
if (i == j) continue;
int x = tmp.compareTo(arr[j]);
if (x < 0)
{
tmp = arr[j];
arr[j] = arr[i];
arr[i] = tmp;
}
}
}
for (int i = 0;i < arr.length;i++)
System.out.println(arr[i]);
}
}
我認爲這是泡沫排序請參閱http://en.wikipedia.org/wiki/Bubble_sort。但它是某種未優化的版本:D – simpletron
感謝simpletron – user3063455