Hi programmers.
I am trying to sort strings with this bubble sort but something is not right. I do not think I am declaring properly temp???
Code:#include <iostream>
#include <string>
using namespace std;
int main()
{
const int NUM_NAMES = 20, SIZE = 17;
int results;
string name;
string 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" };
//Sorting the array//
bool swap;
string temp;
do
{
swap = false;
for (int count = 0; count < (NUM_NAMES - 1); count++)
{
if (names[count] > names[count + 1])
{
temp = names[count];
names[count] = names[count + 1];
names[count + 1] = temp;
swap = true;
}
}
} while (swap);
}