示例#1
0
/**
 * Calcula o tempo de ordenação com a função Clock.
 */
double ordenaVetorClock(int algorithm, int size) {
    clock_t clock_init;

    // Algoritmos de busca
    QuickSort qs = QuickSort();
    BubbleSort bs = BubbleSort();
    MergeSort ms = MergeSort();

    // Escolhe o algoritmo que deve ser testado
    switch (algorithm) {
        case QUICK_SORT:
            clock_init = clock();
            qs.start(vetorQuickSort, size);
            return clock() - clock_init;
        case BUBBLE_SORT:
            clock_init = clock();
            bs.start(vetorBubbleSort, size);
            return clock() - clock_init;
        case MERGE_SORT:
            clock_init = clock();
            ms.start(vetorMergeSort, size);
            return clock() - clock_init;
    }
    return -1;
}
示例#2
0
/**
 * Calcula o tempo de ordenação com a função Clock.
 */
double ordenaVetorTime(int algorithm, int size){
    time_t time_init;

    // Algoritmos de busca
    QuickSort qs = QuickSort();
    BubbleSort bs = BubbleSort();
    MergeSort ms = MergeSort();

    // Escolhe o algoritmo que deve ser testado
    switch (algorithm) {
        case QUICK_SORT:
            time(&time_init);
            qs.start(vetorQuickSort, size);
            return time(NULL) - time_init;
        case BUBBLE_SORT:
            time_init = time(NULL);
            bs.start(vetorBubbleSort, size);
            return time(NULL) - time_init;
        case MERGE_SORT:
            time_init = time(NULL);
            ms.start(vetorMergeSort, size);
            return time(NULL) - time_init;
        default:
            cout << "ERROR" << endl;
        break;
    }
    return -1;
}