Created
May 31, 2013 12:18
-
-
Save arunma/5684616 to your computer and use it in GitHub Desktop.
Insertion Sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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