插入排序

插入排序

 1 public class InsertionSort extends Sort {
 2 
 3     public Comparable[] insertionSort(Comparable[] a) {
 4         int N = a.length;
 5         for (int i = 1; i < N; i++) {
 6             for (int j = i; j > 0 && less(a[j], a[j - 1]); j--) {
 7                 exch(a, j, j - 1);
 8             }
 9         }
10         return a;
11     }
12 
13 }

 

posted @ 2015-07-28 21:21  pepelu  阅读(100)  评论(0编辑  收藏  举报