# include <iostream>
usingnamespace std;
void bubbleSort(string *names, int &i);
void selectionSort (string *names, int &i);
int main()
{
// Variables
string * names = NULL;
int i;
char choice;
// Input & Processing
cout << " This program displays array elements in order." << endl;
cout << " How many names will you enter? : ";
cin >> i;
names = new string[i];
for (int count= 0; count < i; count++)
{
cout << " Enter name: ";
cin >> names[i];
}
names = names - (i -1);
cout << " Which sorting algorithm will be used (Enter B for Bubble sort or S for Selection sort): ";
cin >> choice;
//if ( choice == 'B')
//{
bubbleSort(names, i);
for (int count= 0; count < i; count++)
{
cout << *names;
names++;
}
//}
//else if ( choice == 'S')
//{
//selectionSort(names, i);
//for (int count= 0; count < i; count++)
//{
//cout << *names;
//names++;
//}
//}
}
void bubbleSort(string *names, int &i)
{
bool swap;
string temp;
do
{
swap = false;
for (int count = 0; count < (i - 1); count++)
{
if (names[count] > names [count+1])
{
temp = names[count];
names[count] = names[count+1];
names[count + 1] = temp;
swap = true;
}
}
} while(swap);
}
void selectionSort (string *names, int &i)
{
int start_scan, min_index;
string min_value;
for (start_scan = 0; start_scan < (i - 1); start_scan++)
{
min_index = start_scan;
min_value = names[start_scan];
for (int index = start_scan + 1; index < i; index++)
{
if (names[index]<min_value)
{
min_value = names[index];
min_index = index;
}
}
names[min_index] = names[start_scan];
names[start_scan] = min_value;
}
}
This runs but once I try to use the bubble or selection functions it doesn't work. I commented out the selection function to work on one at a time but I'm at a loss.