冒泡排序-while实现

/**
功能:冒泡排序,从小到大输出。
*/
public class Demo
{
  public static void main(String[] args)
  {
    int[] b=new int[9];
    b=new int[]{8,3,6,1,9,5,4,2,7};
    bubble_sort(b,9);
    for(int i=0;i<9;i++)
    {
      System.out.print(b[i]+" ");
    }
  }
  public static void bubble_sort(int a[],int n)
  {
    int temp;
    while (n>0)
    {
      for(int j=0;j<n-1;j++)
      {
        if(a[j]>a[j+1])
        {
          temp=a[j];
          a[j]=a[j+1];
          a[j+1]=temp;
        }
      }
      n--;
    }
  }
}

原文地址:https://www.cnblogs.com/zhujialei123/p/8018386.html