//比较标准的冒泡排序
public class AdvancedBubbleSort
{
public static void bubbleSort(int[] E,int n)
{
int numPairs;
boolean didSwitch;
int j;
numPairs = n-1;
didSwitch = true;
while(didSwitch)
{
didSwitch = false;
for(j = 0; j < numPairs; j++){
if(E[j] > E[j+1]){
int temp = E[j];
E[j] = E[j+1];
E[j+1] = temp;
didSwitch = true;
}
//if (didSwitch == fail)
}
numPairs = j+1;
}
}
public static void main(String[] args)
{
int E[] = new int[] {
1, 5, 3, 8, 3, 2, 4, -3, 10, 9};
bubbleSort(E, 10);
for (int i = 0; i <= 9; i++) {
System.out.println(E[i]);
}
}
}