java冒泡排序

    技术2022-05-20  36

    public class BubbleSort{ public static void bubbleSort(int[] array) {      for (int i = 0; i < array.length - 1; i++)     {           for(int j = 0; j < array.length - i - 1; j++)   {           if(array[j] > array[j + 1])    {       int temp = array[j];         array[j] = array[j + 1];      array[j + 1] = temp;    }    System.out.println("第" + (i + 1) + "趟排序");          for(int n = 0; n < array.length; n++)          {             System.out.print(array[n] + " ");           }      System.out.println();       }           }   } public static void main(String[] args) { int[] array = {5, 1, 4, 6, 8};        bubbleSort(array); }

    }


    最新回复(0)