Okay, I have this homework assignment which is to sort a 2D array of characters using selection sort.
I've written the selection sort but I can't seem to get it working. (it's not sorting!)
Please tell me what I'm doing wrong, thanks.
[code=c]
void selectionSort(c har array[][SIZE], int rows)
{
const int size = 17;
int startScan, minIndex, index;
char minValue[NUM_NAMES][size];
for (startScan = 0; startScan < (rows - 1); startScan++)
{
minIndex = startScan;
strncpy(minValu e[0], array[startScan], 20);
for (index = startScan + 1; index < rows; index++)
{
if (strcmp(array[index], minValue[NUM_NAMES]) < 0)
{
strncpy(minValu e[0], array[index], 20);
minIndex = index;
}
}
strncpy(array[startScan], array[minIndex] , 20);
}
}[/code]
I've written the selection sort but I can't seem to get it working. (it's not sorting!)
Please tell me what I'm doing wrong, thanks.
[code=c]
void selectionSort(c har array[][SIZE], int rows)
{
const int size = 17;
int startScan, minIndex, index;
char minValue[NUM_NAMES][size];
for (startScan = 0; startScan < (rows - 1); startScan++)
{
minIndex = startScan;
strncpy(minValu e[0], array[startScan], 20);
for (index = startScan + 1; index < rows; index++)
{
if (strcmp(array[index], minValue[NUM_NAMES]) < 0)
{
strncpy(minValu e[0], array[index], 20);
minIndex = index;
}
}
strncpy(array[startScan], array[minIndex] , 20);
}
}[/code]
Comment