It doesn't sort it, all it does is print out the order inwhich things are entered, i'm trying to use a simple bubble sort since the information being sorted is not very large.
void circularList::sortByKey(string key)
{
bool swap = true;
int keyCount = 0;
if(islower(key[keyCount]))
toupper(key[keyCount]); // Make sure the first letter of the name is capitalized
while(keyCount != key.size() && key[keyCount] != '\0')
{
keyCount++;
if(key[keyCount] == ' ' && key[keyCount] != '\0')
key[keyCount] = toupper(key[keyCount + 1]); // Ensure the last name is also capitalized
}
dataNode* temp = head;
dataNode* link = head;
dataNode* sorted = head;
do
{
swap = false;
while(link->next != NULL)
{
// A-Z bubble sort
if(temp->next->customer > key) // If customer > key, both string type
{
sorted = temp;
temp = temp->next;
sorted->next = temp;
swap = true;
}
link = link->next;
}
}while(swap);
cout << "\n\nSorted by key [" << key << "]" << endl;
while( sorted != NULL)
{
cout << sorted->customer << " "
<< sorted->magician << " "
<< sorted->holiday << endl;
sorted = sorted->next;
}
}
I need some help as to where I am going wrong with this.

New Topic/Question
Reply



MultiQuote




|