
//Dione Torrevillas                 CS1A                 Chapter 8, P. 488, #6

/**********************************************************
 * Class: CS1A
 * Chapter 8 Homework - Programming Challenge #6
 * Title: String Selection Sort
 *
 * Description:
 * This program uses selection sort to put an array of 20
 * names in alphabetical order.
 *
 * INPUT:
 * No keyboard input. The names are stored in an array.
 *
 * OUTPUT:
 * The 20 names displayed in alphabetical order.
 **********************************************************/

#include <iostream>
#include <string>
using namespace std;

// Sort a string array alphabetically using selection sort.
void selectionSort(string names[], int size)
{
    for (int start = 0; start < size - 1; start++)
    {
        int minIndex = start;

        // Find the alphabetically first remaining name.
        for (int i = start + 1; i < size; i++)
        {
            if (names[i] < names[minIndex])
                minIndex = i;
        }

        // Move that name into its correct position.
        string temp = names[start];
        names[start] = names[minIndex];
        names[minIndex] = temp;
    }
}

int main()
{
    const int NUM_NAMES = 20;

    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"
    };

    // The driver program calls the modified selection sort function.
    selectionSort(names, NUM_NAMES);

    //OUTPUT - Display all of the sorted names.
    cout << "Names in alphabetical order:" << endl;

    for (int i = 0; i < NUM_NAMES; i++)
        cout << names[i] << endl;

    return 0;
}
