public void BubbleSortArrayString(string[] letters) //change here
{
bool swap;
string temp; //change this too
do
{
swap = false;
for (int index = 0; index < (letters.Length - 1); index++)
{
if (letters[index] > letters[index + 1]) //if first number is greater then second then swap
{
//swap
temp = letters[index];
letters[index] = letters[index + 1];
letters[index + 1] = temp;
swap = true;
}
}
} while (swap == true);
}
I have managed to bubble sort a decimal but I'm suck with a string, I have a text file with months in it and I need to sort it in alphabetical order. I get the error:
operator > cannot be applied to type string and string
Help would be appreciated.
== trueis unnecessary since it is just evaluating whether your boolean value equals another boolean value to return a boolean value, since you already have a boolean value to start with you can just use that (while(swap))