Java 排序问题

来源:互联网 发布:和明星合影软件 编辑:程序博客网 时间:2024/04/30 23:26

1.冒泡排序

public class BubbleSortPractice {public static void BubbleSort(int[] a){for(int i = 0; i < a.length - 1; i++){for(int j = 0; j < a.length - i - 1; j++){if(a[j] > a[j + 1]){   int temp = a[j];   a[j] = a[j+1];   a[j+1] = temp;}}System.out.print("第" + ( i + 1)+ "趟输出" + " ");for(int k = 0; k < a.length; k++){System.out.print(a[k]);    }System.out.println();}}public static void main(String[] args){int[] a = {9,8,7,6,5,4,3,2,1,0};BubbleSort(a);}}


原创粉丝点击