java实现冒泡排序算法程序

来源:互联网 发布:淘宝买家秀招聘 编辑:程序博客网 时间:2024/05/17 22:53

package ff;//在eclipse中实现的,需导包

public classdf {

    public static void main(String[] args) {

        dft=newdf();

        int []b={3,1,12,5,4,8,6};

        t.bubble(b);

        System.out.println("最终冒泡法排序结果");

    for(int i=0;i<b.length;i++)

    {

        System.out.print(b[i]+"\t");

    }}

     public  void bubble(int[]a) {

             int temp;

             for(inti=a.length-1;0<i;i--)

           for(int j=0;j<i;j++)

             { if(a[j]>a[j+1])

                 { temp=a[j];

                      a[j]=a[j+1];

                      a[j+1]=temp;

                  }

}

}