Am using 3 parallel arrays and using a selection sort that is to sort by miles in descending order. It does sort in descending order but when for example i enter data in the input file as follows:
- NC 33.9 5
- VA 22.2 0
- etc.
Then the program will print the 'VA' data twice and not display the 'NC' data. Parallel arrays not my idea neither is the selection sort. They are required. please help
void sortEntries( string initials[], double miles[], int shelters[] )
{
int top, bottom, i, n;;
string tempInitials;
double tempMiles;
int tempShelters;
//Selection sorting for initials[]
n = 14;
for( top = 0; top < MAX_ENTRIES - 1; top++ )
{
tempInitials = initials[smallest];
tempMiles = miles[smallest];
tempShelters = shelters[smalles];
smallest = top;
//Locate smallest number between 1 and MAX_ENTRIES(14)
for ( i = top; i < MAX_ENTRIES; i++ )
{
if ( initials[i] < tempMiles )
{
tempInitials = initials[i];
tempMiles = miles[i];
tempShelters = shelters[i];
smallest = i;
}
}
initials[top] = initials[smallest];
miles[top] = miles[smallest];
shelters[top] = shelters[smallest];
initials[smallest] = tempInitials;
miles[smallest] = tempMiles;
shelters[smallest] = tempShelters;
}