package com.sytdc.cxl; /** * * @author ailaopo * * */ public class TestSortDesc { private static final int M=10; public static void main(String args[]){ //Sort1(); Sort2(); } //选择排序算法 public static void Sort2(){ int A[] = {2,4,8,9,56,74,89,20,51,31}; int temp = 0; for(int j = 0; j <M; j++){ System.out.println("#######start loop1#########"+String.valueOf((j+1))); for(int i = 0; i <M-1; i++){ if(A[i] < A[i+1]){ temp = A[i]; A[i] =A[i+1]; A[i+1] = temp; for (int k=0; k < M; k++ ){ System.out.print(A[k]); if(k==M-1){ System.out.println(); } else { System.out.print(","); } } } } System.out.println("#######end loop1#########"+String.valueOf((j+1))); } System.out.println("*****start******"); for(int i = 0; i < M; i++){ System.out.println(A[i]); } System.out.println("*****end******"); } } 运行结构如下 #######start loop1#########1 4,2,8,9,56,74,89,20,51,31 4,8,2,9,56,74,89,20,51,31 4,8,9,2,56,74,89,20,51,31 4,8,9,56,2,74,89,20,51,31 4,8,9,56,74,2,89,20,51,31 4,8,9,56,74,89,2,20,51,31 4,8,9,56,74,89,20,2,51,31 4,8,9,56,74,89,20,51,2,31 4,8,9,56,74,89,20,51,31,2 #######end loop1#########1 #######start loop1#########2 8,4,9,56,74,89,20,51,31,2 8,9,4,56,74,89,20,51,31,2 8,9,56,4,74,89,20,51,31,2 8,9,56,74,4,89,20,51,31,2 8,9,56,74,89,4,20,51,31,2 8,9,56,74,89,20,4,51,31,2 8,9,56,74,89,20,51,4,31,2 8,9,56,74,89,20,51,31,4,2 #######end loop1#########2 #######start loop1#########3 9,8,56,74,89,20,51,31,4,2 9,56,8,74,89,20,51,31,4,2 9,56,74,8,89,20,51,31,4,2 9,56,74,89,8,20,51,31,4,2 9,56,74,89,20,8,51,31,4,2 9,56,74,89,20,51,8,31,4,2 9,56,74,89,20,51,31,8,4,2 #######end loop1#########3 #######start loop1#########4 56,9,74,89,20,51,31,8,4,2 56,74,9,89,20,51,31,8,4,2 56,74,89,9,20,51,31,8,4,2 56,74,89,20,9,51,31,8,4,2 56,74,89,20,51,9,31,8,4,2 56,74,89,20,51,31,9,8,4,2 #######end loop1#########4 #######start loop1#########5 74,56,89,20,51,31,9,8,4,2 74,89,56,20,51,31,9,8,4,2 74,89,56,51,20,31,9,8,4,2 74,89,56,51,31,20,9,8,4,2 #######end loop1#########5 #######start loop1#########6 89,74,56,51,31,20,9,8,4,2 #######end loop1#########6 #######start loop1#########7 #######end loop1#########7 #######start loop1#########8 #######end loop1#########8 #######start loop1#########9 #######end loop1#########9 #######start loop1#########10 #######end loop1#########10 *****start****** 89 74 56 51 31 20 9 8 4 2 *****end******