快速插入排序、冒泡排序

快速插入排序
public InsertSort() {
             int[] a = { 12, 32, 34, 2, 3, 4, 54, 234, 6, 65, 34, 2, 3, 534, 6 };
             int temp = 0;
             for (int i = 1; i < a.length; i++) {
                   int j = i - 1;
                  temp = a[i];
                   for (; j >= 0 && temp < a[j]; j--) {
                        a[j + 1] = a[j];
                  }
                  a[j + 1] = temp;
            }
             for (int i = 1; i < a.length; i++) {
                  System. out.println(a[i]);
            }
      }

       public static void main(String[] s) {
             new InsertSort();
      }

冒泡排序:
public void mopao() {
             int[] a = { 12, 32, 34, 2, 3, 4, 54, 234, 6, 65, 34, 2, 3, 534, 6 };
             for (int i = 0; i < a.length; i++) {
                   for (int k = 0; k < a.length; k++) {
                         if (a[i] < a[k]) {
                               int temp = 0;
                              temp = a[i];
                              a[i] = a[k];
                              a[k] = temp;
                        }
                  }
            }
             for (int i = 1; i < a.length; i++) {
                  System. out.println(a[i]);
            }
      }

  

posted @ 2012-08-16 18:58  园林鸟  阅读(322)  评论(0编辑  收藏  举报