Monday, December 12, 2011

Insertion Sort


public static int[] insertion(int[] a){
int key;
for(int j=1;j<a.length;j++ ) {
key=a[j];
  int i=j-1;
while(i >= 0 && a[i] > key){
a[i+1] = a[i];
i--;
}
a[i+1] = key;
}
return a;
}

No comments:

Post a Comment