冒泡排序

冒泡排序

package com.cafuc;

import java.util.Arrays;

public class MaoPaoSort {
  public static void main(String[] args) {
      int a[]={10,80,6,3,5,86};
      int[] sort = sort(a);
      System.out.println(Arrays.toString(a));


  }

  //冒泡排序
  public static int[] sort(int[] arrays){
      int temp;
      for (int i = 0; i < arrays.length-1; i++) {
          //外层循环,计算走了几次
          for (int j = 0; j < arrays.length-1; j++) {
              if (arrays[j+1]<arrays[j]){
                  temp=arrays[j];
                  arrays[j]=arrays[j+1];
                  arrays[j+1]=temp;
              }
          }

      }
      return arrays;
  }
}

 

posted @ 2021-06-13 21:33  库里在线  阅读(56)  评论(0)    收藏  举报