对一维整数数组{23,14,5,12,8,10,32,41,6,56}进行升幂排序,输出排序后的结果。
package com; public class Demo1_3 { public static void main(String[] args) { // TODO Auto-generated method stub int arr[] = { 23,14,5,12,8,10,32,41,6,56 }; int i, j; for (i = 8; i >= 0; i--) { for (j = 0; j <= i; j++) { if (arr[j] > arr[j + 1]) { int temp; //排序三步法 temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } } System.out.print("最终排序:"); for (i = 0; i < 10; i++) { System.out.print( arr[i]+" " ); } } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)