标签:
画图分析:
代码分析:
1 package com.paixu; 2 3 public class xuanzepaixu { 4 public static void main(String[] args) { 5 int [] arr = {25,24,99,101,100,552,32,333,5555,99999,686,4598,32,3657,12,11,22,88}; 6 System.out.println("排序前:"); 7 iterator(arr); 8 System.out.println("-----------------------"); 9 //第一次排序 10 int x = 0; 11 for(int y = x+1;y<arr.length;y++){ 12 if(arr[x]>arr[y]){ 13 int temp = arr[x]; 14 arr[x] = arr[y]; 15 arr[y] = temp; 16 } 17 } 18 System.out.println("第一次排序后:"); 19 iterator(arr); 20 System.out.println("-----------------------"); 21 //.... 22 xuanzepaixu(arr); 23 } 24 25 //选择排序 26 public static void xuanzepaixu(int []arr){ 27 for(int i = 0;i<arr.length-1;i++){ 28 for(int j = i+1;j<arr.length;j++){ 29 if(arr[i]>arr[j]){ 30 int temp = arr[i]; 31 arr[i] = arr[j]; 32 arr[j] = temp; 33 } 34 } 35 36 } 37 System.out.println("排序后:"); 38 iterator(arr); 39 } 40 41 42 //遍历数组 43 public static void iterator(int[] arr){ 44 System.out.print("["); 45 for(int x = 0;x<arr.length;x++){ 46 if(x == arr.length-1){ 47 System.out.println(arr[x]+"]"); 48 }else{ 49 System.out.print(arr[x]+","); 50 } 51 } 52 } 53 }
标签:
原文地址:http://www.cnblogs.com/jiangjianzhu/p/5798409.html