1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
int main()
{
const int NUM_NAMES = 20, SIZE = 17;
char names[NUM_NAMES][SIZE] = { "Collins, Bill", "Smith, Bart", "Allen, Jim",
"Griffin, Jim", "Stamey, Marty", "Rose, Geri",
"Taylor, Terri", "Johnson Jill", "Allison, Jeff",
"Looney, Joe", "Wolfe, Bill", "James, Jean",
"Weaver, Jim", "Pore, Bob", "Rutherford, Greg",
"Javens, Renee", "Harrison, Rose", "Setzer, Cathy",
"Pike, Gordon", "Holland, Beth" };
int startScan, minIndex;
char minValue[SIZE];
for(startScan = 0; startScan = (NUM_NAMES - 1); startScan++)
{
minIndex = startScan;
for(int i = 0; i < SIZE; i++)
minValue[i] = names[startScan][i];
for(int index = startScan + 1; index < NUM_NAMES; index++)
{
if(names[index][0] < minValue[0])
{
for(int i = 0; i < SIZE; i++)
minValue[i] = names[startScan][i];
minIndex = index;
}
}
for(int i = 0; i < SIZE; i++)
names[minIndex][i] = names[startScan][i];
for(int i = 0; i < SIZE; i++)
names[startScan][i] = minValue[i];
}
for(int i = 0; i < NUM_NAMES; i++)
{
for(int j = 0; j < SIZE; j++)
cout << names[i][j];
cout << endl;
}
return 0;
}
|