@@ -0,0 +1,1620 @@
+package week3;%0A%0Aimport java.util.Random;%0A%0A/**%0A * Author: Mark%0A * Date  : 2015/3/2%0A * Time  : 20:47%0A */%0Apublic class MergeSort%3CItem extends Comparable%3C? super Item%3E%3E %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A        Integer%5B%5D items = new Integer%5B10%5D;%0A        Random random = new Random(47);%0A        for (int i = 0; i %3C 10; i++) %7B%0A            items%5Bi%5D = random.nextInt(50);%0A        %7D%0A        printArray(items);%0A        new MergeSort%3CInteger%3E().sort(items, 0, items.length);%0A        printArray(items);%0A    %7D%0A%0A    private static void printArray(Comparable%5B%5D items) %7B%0A        for (Comparable i : items) %7B%0A            System.out.print(i + %22 %22);%0A        %7D%0A        System.out.println();%0A    %7D%0A%0A%0A    @SuppressWarnings(%22unchecked%22)%0A    public void sort(Item%5B%5D items, int low, int high) %7B%0A        Item%5B%5D tmp = (Item%5B%5D) new Comparable%5Bitems.length%5D;%0A        mergeSort(items, tmp, low, high);%0A    %7D%0A%0A    private void mergeSort(Item%5B%5D items, Item%5B%5D tmp, int low, int high) %7B%0A        if (high - low %3C= 1) return;%0A        int mid = low + (high - low) / 2;%0A        mergeSort(items, tmp, low, mid);%0A        mergeSort(items, tmp, mid, high);%0A        merge(items, tmp, low, mid, high);%0A    %7D%0A%0A    private void merge(Item%5B%5D items, Item%5B%5D tmp, int low, int mid, int high) %7B%0A        System.arraycopy(items, low, tmp, low, high - low);%0A        int i = low, j = mid;%0A        for (int k = low; k %3C high; k++) %7B%0A            if (i %3E= mid) items%5Bk%5D = tmp%5Bj++%5D;%0A            else if (j %3E= high) items%5Bk%5D = tmp%5Bi++%5D;%0A            else if (tmp%5Bi%5D.compareTo(tmp%5Bj%5D) %3C 0) items%5Bk%5D = tmp%5Bi++%5D;%0A            else items%5Bk%5D = tmp%5Bj++%5D;%0A        %7D%0A    %7D%0A%0A%7D%0A

add mergesort