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 41 42 43 44 45 46 47 48 49
|
#include <iostream>
#include <string>
using namespace std;
//Sort Function Prototype
void arraySort(string, const int);
//Array Size
const int NUM_NAMES = 20;
int main()
{
string names[NUM_NAMES] = {"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"};
//Array Sort Function Call
arraySort(names, NUM_NAMES);
}
//Array Sort function
void arraySort(string names[], const int NUM_NAMES)
{
int startScan, minIndex, minValue;
for (startScan = 0; startScan < (NUM_NAMES - 1); startScan++)
{
minIndex = startScan;
minValue = names[startScan];
for (int index = startScan + 1; index < NUM_NAMES; index++)
{
if (names[index] < minValue)
{
minValue = names[index];
minIndex = index;
}
}
names[minIndex] = names[startScan];
names[startScan] = minValue;
}
}
|