When I run my full program, array1 sorts perfectly. However, the values that go along with array1, which are stored in the same location in array2, don't change to the same location.
void sortArrays(string array1[MAX_NUM], int array2[MAX_NUM], int count1)//Sorts the arrays from highest to lowest
//, based on ID number
{
int i, j, pos;
int buff[MAX_NUM];
string temp;
int temp2;
for (i = count1-1; i > 0; i--)
{
pos = 0; // initialize to subscript of first element
for (j = 0; j <= i; j++) // locate smallest between positions 1 and i.
{
if (array1[j] < array1[pos])
pos = j;
}
temp = array1[pos]; // Swap smallest found with element in position i.
temp2 = buff[pos];
array1[pos] = array1[i];
buff[pos] = buff[i];
array1[i] = temp;
buff[pos] = temp2;
}
array2 = buff;
}
Yes, it should be. But unfortunately that didn't change anything. I also have this way of doing it, but it sorts it in the opposite order than it needs to be in, but the data does stay together.
void sortArrays(string array1[MAX_NUM], int array2[MAX_NUM], int count1)//Sorts the arrays from highest to lowest
//, based on ID number
{
int curTop, // Current top of unsorted list
tryIdx, // Position to compare value to
minPosition; // Position of smallest value
string temp;
int temp2; // Temp value for swapping
// for each item in the list (top to bottom)
for (curTop = 0; curTop < count1 - 1; curTop++)
{
minPosition = curTop; // start with current top as smallest value
// find smallest value from curTop down
for (tryIdx = curTop + 1; tryIdx < count1; tryIdx++)
if (array1[tryIdx] < array1[minPosition])
minPosition = tryIdx;
// if smallest not at curTop, swap with curTop
if (minPosition != curTop)
{
temp = array1[curTop];
temp2 = array2[curTop];
array1[curTop] = array1[minPosition];
array2[curTop] = array2[minPosition];
array1[minPosition] = temp;
array2[minPosition] = temp2;
} // end swap
} // end for
return;
}