示例#1
0
int main(int, char*[])
{
    test_quick();
    test_short_messages();
    test_long();
    
    return boost::report_errors();
}
示例#2
0
int main()
{
    auto empty = std::vector<int> {};
    auto singleton = std::vector<int> { 1 };
    auto doubleton = std::vector<int> { 1, 2 };
    auto random = std::vector<int> { 5, 1, 3, 4, 8, 7, 2, 9, 0, 6 };
    auto sorted = std::vector<int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    auto reversed = std::vector<int> { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
    auto nearly_sorted = std::vector<int> { 0, 1, 3, 2, 4, 5, 7, 6, 8, 9 };
    auto few_unique = std::vector<int> { 0, 1, 2, 0, 1, 2, 0, 1, 2, 0 };

    auto inputs = std::vector<std::vector<int>> { empty, singleton, doubleton, random, sorted, reversed, nearly_sorted, few_unique };


    clock_t t;

    t = clock();
    test_selection(begin(inputs), end(inputs));
    t = clock() - t;
    double time_taken = ((double)t)/CLOCKS_PER_SEC; // in seconds
    printf("selection_sort took %f seconds to execute \n\n", time_taken);

    t = clock();
    test_insertion(begin(inputs), end(inputs));
    t = clock() - t;
     time_taken = ((double)t)/CLOCKS_PER_SEC; // in seconds
    printf("insertion_sort took %f seconds to execute \n\n", time_taken);

    t = clock();
    test_quick(begin(inputs), end(inputs));
    t = clock() - t;
     time_taken = ((double)t)/CLOCKS_PER_SEC; // in seconds
    printf("quick_sort took %f seconds to execute \n\n", time_taken);

    t = clock();
    test_merge(begin(inputs), end(inputs));
    t = clock() - t;
     time_taken = ((double)t)/CLOCKS_PER_SEC; // in seconds
    printf("merge_sort took %f seconds to execute \n\n", time_taken);

    t = clock();
    test_heap(begin(inputs), end(inputs));
    t = clock() - t;
    time_taken = ((double)t)/CLOCKS_PER_SEC; // in seconds
    printf("heap_sort took %f seconds to execute \n\n", time_taken);
}