冒泡排序递归

    xiaoxiao2022-07-14  151

    package com.imooc.ten; import java.util.Arrays; public class MaoPaoRecursion { public static int[] bubbleSort(int[] array,int size) { //boolean flag=true; if (size== 0) return array; for (int j = 0; j <size-1; j++) if (array[j + 1] < array[j]) { int temp = array[j + 1]; array[j + 1] = array[j]; array[j] = temp; //flag=false; } bubbleSort(array,--size); //if(flag) //break; return array; } public static void main(String[] args) { // TODO Auto-generated method stub int [] arr= {9,8,7,6,5,4,3,2,1}; //int [] arr= {1,2,3,4,5,6,7,8,9}; MaoPaoRecursion maopao=new MaoPaoRecursion(); maopao.bubbleSort(arr, arr.length); System.out.println(Arrays.toString(arr)); } }

     

    最新回复(0)