算法(Algorithms)第4版 练习 2.2.23

测试结果:

算法(Algorithms)第4版 练习 2.2.10

算法(Algorithms)第4版 练习 2.2.11(1)

算法(Algorithms)第4版 练习 2.2.11(2)

算法(Algorithms)第4版 练习 2.2.11(3)

算法(Algorithms)第4版 练习 2.2.11(最终)

 

测试代码:

package com.qiusongde;

import edu.princeton.cs.algs4.StdOut;

public class Exercise2223 {

    public static void main(String[] args) {
        
        int N = 20000;
        int T = 1000;
        
        String alg1 = "Merge";
        String alg2 = "MergeFasterM";
        String alg3 = "MergeUseInsert";
        String alg4 = "MergeSkipMerge";
        String alg5 = "MergeAvoidCopy";
        String alg6 = "MergeX";
        
        double t1 = SortCompare.timeRandomInput(alg1, N, T);
        double t2 = SortCompare.timeRandomInput(alg2, N, T);
        double t3 = SortCompare.timeRandomInput(alg3, N, T);
        double t4 = SortCompare.timeRandomInput(alg4, N, T);
        double t5 = SortCompare.timeRandomInput(alg5, N, T);
        double t6 = SortCompare.timeRandomInput(alg6, N, T);
        
        StdOut.printf("For %d random Doubles %d trials\n", N, T, alg1);
        StdOut.printf(
                "%s is %.1fs\n"
                + "%s is %.1fs\n"
                + "%s is %.1fs\n"
                + "%s is %.1fs\n"
                + "%s is %.1fs\n"
                + "%s is %.1fs\n", 
                alg1, t1, 
                alg2, t2, 
                alg3, t3, 
                alg4, t4, 
                alg5, t5,
                alg6, t6);
        
    }

}

 

posted @ 2017-03-24 22:53  我是老邱  阅读(320)  评论(0编辑  收藏  举报