我正在嘗試實(shí)現(xiàn)一種快速排序算法來對(duì)浮點(diǎn)數(shù)組進(jìn)行排序。每當(dāng)我引用數(shù)組中的索引時(shí),我都會(huì)收到此錯(cuò)誤:無法將類型“float”隱式轉(zhuǎn)換為“int”。存在顯式轉(zhuǎn)換(您是否缺少轉(zhuǎn)換)?這是算法:class Quicksort{ public static void Sort(float[] numbers, int left, int right) { float i = Convert.ToSingle(left); float j = Convert.ToSingle(right); var pivot = numbers[(left + right) / 2]; while (i <= j) { while (numbers[i] < pivot) //ERROR HERE i++; while (numbers[j] > pivot) //ERROR HERE j--; if (i <= j) { float tmp = numbers[i]; //ERROR HERE numbers[i] = numbers[j]; //ERROR HERE numbers[j] = tmp; //ERROR HERE i++; j--; } } if (left < j) Sort(numbers, left, j); if (i < right) Sort(numbers, i, right); }}numbers[i]每當(dāng)我使用或時(shí)出現(xiàn)轉(zhuǎn)換錯(cuò)誤numbers[j]我將如何解決這個(gè)問題?
如何修復(fù)我的 C# 快速排序算法中的隱式轉(zhuǎn)換錯(cuò)誤?
慕工程0101907
2022-12-24 10:54:13