I need to measure time of some sorting algorithms. The problem is that some funcions(algorithms) might have 2 arguments(bubble sort for example) or 3 arguments(quick sort). I don't have idea how to prepare my function to accept both type of functions(2-arguments and 3-arguments).
I was thinking about add some default argument to every function which have only 2 arguments and then in my get_time_calculations
declares it like this:
double get_time_calculations(void (*f)(int *, int, int), int *tab, int n) {
...
}
But this solution is only workaround, and maybe there is a better way to did this without changing arguments of prepared algorithms?
My function to measure execution of function time:
double get_time_calculations(void (*f)(int *, int), int *tab, int n) {
clock_t begin, end;
begin = clock();
f(tab, n);
end = clock();
randomize(tab, n, -100, 201);
return (double)(end - begin)/CLOCKS_PER_SEC;
}
And my function to test all algorithms:
void test1(int *ran_tab, int n) {
cout << endl << "Insert sort: " << get_time_calculations(insert_sort, ran_tab, n) << "ms" << endl;
cout << endl << "Bubble sort: " << get_time_calculations(bubble_sort, ran_tab, n) << "ms" << endl;
cout << endl << "Selection sort: " << get_time_calculations(selection_sort, ran_tab, n) << "ms" << endl;
cout << endl << "Quick sort: " << get_time_calculations(quick_sort, ran_tab, n) << "ms" << endl;
cout << endl << "Shell sort: " << get_time_calculations(shell_sort, ran_tab, n) << "ms" << endl;
cout<<endl<<"Heap sort: "<<get_time_calculations(heap_sort, ran_tab, n)<<"ms"<<endl;
}