Insertion Sort JAva with tech kid
Sort
package com.google;
public class InsertionSort {
public static void main(String[] args) {
int [] a = {2,1,5,4,7,9,3};
for (int i = 1 ;i<a.length-1; i++){
int temp = a[i];
int j = i-1 ;
while( j>=0 &&temp < a[j]){
a[j+1] = a[j] ;
j = j-1;}
a[j+1] = temp ;}
for (int x = 0 ;x<a.length; x++){
System.out.println(a[x]);
}
}
}

Comments
Post a Comment