Derrick567
12/4/2016 - 11:12 AM

InsertionSort.java

InsertionSort:

int arr[] = {32,41,59,26,41,58};
  
  for(int j=1;j<arr.length;j++){
   int key = arr[j];
   int i = j-1;
   while(i>-1 && arr[i]>key){
    arr[i+1]=arr[i];
    i--;
   }
   arr[i+1]=key;
  }
  

               //印出結果
  for(int i=0;i<arr.length;i++){
   System.out.print(arr[i]+" ");
  }
 }