void sortowanie_wybor(long int* tab,long int a,long int n)
{
int w;
int minn;
for(int i=0; i<n; i++)
{
minn=tab[i];
for(int j=i; j<n; j++)
{
if(minn>tab[j])
{
w=j;
minn=tab[j];
}
}
int temp;
temp=tab[w];
tab[w]=tab[i];
tab[i]=temp;
}
}
void sortowanie_bubble(long int* tab,long int a,long int n)
{
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
if(tab[i]<tab[j])
{
int temp;
temp=tab[i];
tab[i]=tab[j];
tab[j]=temp;
}
}
}
}
void test(long int size)
{
long int T[99999];
for(int i=0; i<99999; i++)
{
T[i]=i;
}
double insertion_sort_time = 0;
double insertion_sort_time1 = 0;
double test1 = 0;
clock_t start, end;
long int *a = generate_random_array(size);
long int *b = copy_array(a,size);
start = clock();
sortowanie_wybor(b,0,size-1); //wywolanie algorytmu sorotowania
end = clock();
insertion_sort_time += ((double) (end - start)) / CLOCKS_PER_SEC;
free(b);
long int *c = copy_array(a,size);
start = clock();
sortowanie_bubble(c,0,size-1);
end = clock();
insertion_sort_time1 += ((double) (end - start)) / CLOCKS_PER_SEC;
free(c);
start =clock();
sortowanie_wybor(c,0,size-1);
end = clock();
test1 += ((double) (end - start)) / CLOCKS_PER_SEC;
std::cout << " Czas sortowania(wybor) " << insertion_sort_time << endl;
std::cout << "Czas sortowania(bubble) " << insertion_sort_time1 << endl;
std::cout << "Czas sortowania(max) " << test1 <<endl;
Mam program sprawdzający czas sortowania ale działa on tak jak trzeba a sam nie mogę znaleźć błędu. Nie rozumie dlaczego liczy czas jeśli jeden sortuje malejąca a drugi rosnąco ale już nie liczy poprawnie jeśli oba sortują malejąco i nie działa jeśli tworzę tablice posortowaną odwrotnie.