import java.util.Arrays; public class TestBubbleSort2 { public static void main(String[] args) { int[] values = { 3, 1, 6, 2, 9, 0, 7, 4, 5, 8 }; int temp = 0; for(int i=0;i<values.length-1;i++) { boolean flag = true; for(int j=0;j<values.length-1-i;j++) { if(values[j] > values[j+1]) { temp = values[j]; values[j] = values[j+1]; values[j+1] = temp; flag = false; } System.out.println(Arrays.toString(values)); } if(flag) { break; } System.out.println("#####################"); } } }
原文地址:https://www.cnblogs.com/kl-1998/p/10716171.html
时间: 2024-10-01 00:38:08