Mam kod sortowanie przez wybieranie.
Jak zmienić aby tez była wyświetlana ilość zamian przy sortowaniu?
#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
void selectionsort(int n, int t[]);
int main(void)
{
int tab[20];
srand(time(NULL));
for(int i=0; i<20; i++) {
tab[i] = rand()%100;
cout << tab[i] << " ";
}
cout << endl;
selectionsort(20, tab);
for(int i=0; i<20; i++) cout << tab[i] << " ";
cout << endl;
return 0;
}
void selectionsort(int n, int t[])
{
int i, j, k;
for(i=0; i<n; i++) {
k=i;
for(j=i+1; j<n; j++) if(t[j]<t[k]) k=j;
swap(t[k], t[i]);
}
}