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);
}
我已经设法对小数点进行冒泡排序,但是我用字符串来吮吸,我有一个带有月份的文本文件,我需要按字母顺序排序。我得到的错误:如何对字符串数组进行冒泡排序?
operator > cannot be applied to type string and string
帮助,将不胜感激。
FYI:'==真'是不必要的,因为它仅仅是评估您的布尔值是否等于另一个布尔值返回一个布尔值,因为你已经有一个布尔值开始,你可以使用('while(swap)') – Sayse