アルゴリズム(1)-発泡体の並べ替え


泡のアルゴリズムの核心は2層のfor循環です.時間複雑度O(n^2)
    public static void bubbleSort(int[] a) {

        for (int i=0;ia[j]){//    
                    int temp=a[j];//      
                    a[j]=a[i];
                    a[i]=temp;
                }
            }
        }
    }

    public static void main(String[] args) {
        int i;
        int a[] = {30,40,60,10,20,50,70,31};
        bubbleSort(a);
        System.out.printf("after  sort:");
        for (i=0; i