Linux教程網
- public class Test {
-
- static void Insert(int a[])
- {
- int j;
- for (int i = 1; i < a.length; i++) {//把第一個數作為基點,後面的數都和它比較
- int temp=a[i];
- j=i;
- while (j>0&&(a[j-1]>=temp)) {
- a[j]=a[j-1];
- --j;
- }
- a[j]=temp;
- System.out.print("\n第"+i+"次的結果是:");
- for (int k = 0; k < a.length; k++) {
- System.out.print(a[k]+" ");
- }
- System.out.println();
- }
- }
-
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int Arra[] =new int[]{2,4,6,1,3};
- Insert(Arra);
- for (int i = 0; i < Arra.length; i++) {
- System.err.print(Arra[i]+" ");
- }
- }
-
- }
Copyright ©
Linux教程網 All Rights Reserved