Skip to content

Instantly share code, notes, and snippets.

@arunma
Created May 31, 2013 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arunma/5684616 to your computer and use it in GitHub Desktop.
Save arunma/5684616 to your computer and use it in GitHub Desktop.
Insertion Sort
package com.sorting.insert;
import static com.sorting.insert.SortUtils.*;
public class InsertionSort {
public Comparable[] sort(Comparable[] items) {
for (int i=0;i<items.length;i++){
for (int j=i;j>0;j--){
if (less (items[j],items[j-1])){
exchange(items, j, j-1);
}
else{
break;
}
}
}
return items;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment