Home:ALL Converter>How to use bubble sort for sorting custom class strings in ascending order

How to use bubble sort for sorting custom class strings in ascending order

Ask Time:2019-06-01T16:04:52         Author:Alexander Ritzie

Json Formatter

I'm currently trying to finish up this program for my CS class, and all I have left to do is sort the strings in ascending order. I'm trying to use a bubble sort, but it's not liking some of the operations. Also, just a note that might be useful, the class that we had to make for this program is essentially a custom string class with custom functions and operator overloads.

I've tried moving the stored string in the AIRString vector back into an AIRString variable, but it wouldn't take it. I think that it's because of how the assignment operator overload is written, causing it to not accept a vector as an acceptable value. I've also tried directly outputting the string inside the vector, but it didn't take this either.

<< operator overload

ostream & operator<<(ostream & ostrm, const AIRString & rval)
{
    ostrm << rval.str;
    return ostrm;
}

Bubble Sort

for (int i = 0; i < strCount - 1; i++) {
        for (int j = i + 1; j < strCount; j++) {
            if (storedStr[strCount] < storedStr[strCount + 1]) {
                fout << storedStr[strCount] << endl;
            }
        }
    }

Note that storedStr is an AIRString variable and that all other variable in the bubble sort are int variables.

I'm essentially wanting to print the strings out to an output file as they are sorted. The error that I get with the current code is "no operator "<<" matches these operands". I'm not quite sure how to fix this, so any help would be appreciated.

Author:Alexander Ritzie,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/56404939/how-to-use-bubble-sort-for-sorting-custom-class-strings-in-ascending-order
yy