Hi! Im trying to make a program where I fill an array with elements from my defined class cars in cars.h /cars.cpp, and then sort the elements by using the selectionsort algoritm. Im guessing I have to replace my filling of the tab with random numbers with something like Cars<int>Cars[10]?
void selectionSort(int *tab, int antall){
int indexLargestSoFar;
int temp;
for(int i=antall-1; i>=1; --i)
{
indexLargestSoFar=0;
for(int j=1;j<=i;++j)
{
if(tab[j]>tab[indexLargestSoFar]){
indexLargestSoFar = j;
}
}
temp=tab[i];
tab[i]=tab[indexLargestSoFar];
tab[indexLargestSoFar]=temp;
}
}
void main(){
const int tab_length = 10;
int tab[tab_length];
srand((unsigned int)time(NULL));
cout << "Filling the tab with 10 elements" << endl;
for(int i=0; i<tab_length;++i)
{
tab[i]=abs(rand()%10);
//SUPPOSE THIS IS THE PLACE TO FILL IN......
}
for(int i = 0; i < 10; ++i)
{
cout << tab[i] << " " <<endl;
}
//cout << " " <<endl;
cout<<"Sorterer tabellen....." <<endl;
selectionSort(tab,tab_length);
for(int i = 0; i < 10; ++i)
{
cout << tab[i] << " " << endl;
}
Hope someone could give me a clue what to do next..