class="lazy img-rounded" src="/Upload/Images/2014072815/BE83AB97EA2271D5.jpg" style="font-size: 12px; height: auto; max-width: 100%; vertical-align: middle; border: 0px; border-top-left-radius: 6px; border-top-right-radius: 6px; border-bottom-right-radius: 6px; border-bottom-left-radius: 6px; margin-right: 5px; color: #9f9f9f; display: inline;">
运行此方法需要为main方法传递参数
package com.zuidaima.sort; /** *@author www.zuidaima.com **/ public class TestSort { public static void main(String args[]){ int l = args.length; int[] a = new int[l]; for(int i = 0;i < l;i++){ a[i] = Integer.parseInt(args[i]); } for(int i = 0;i < l;i++){ int k = i; int j; for(j = k + 1;j < l;j++){ if(a[j] < a[k]){ k = j; } } System.out.print("j = " + j); if(k != i){ int temp = a[i]; a[i] = a[k]; a[k] = temp; } } System.out.println(); for(int i = 0;i < l;i++){ System.out.print(" a[" + i +"]:" + a[i]); } } }
标签:?算法?排序?插入?java话题:?语言基础
?