我的代码如下。它是一个包含在项目中的排序方法,而不是用于代码效率的bubblesort。我的问题是我不断收到错误:
array required, but java.util.List<Inpatient> found
&安培;
QuickSort(java.util.List<Inpatient>,int,int) in UtilitiesInpatient cannot be applied to (int,int)
我尝试过做一些研究,但很多算法的变化很大,取决于字符串或整数排序,而且对错误本身的研究也非常无益。非常感谢任何帮助或提示!
public void QuickSort (List<Inpatient> inpatientArrayListIn, int first, int last)
{
// Quick Sort
List<Inpatient> pivotValue = new ArrayList<Inpatient>();
List<Inpatient> lowerPointerValue = new ArrayList<Inpatient>();
List<Inpatient> upperPointerValue = new ArrayList<Inpatient>();
int pivotIndex = first;
Inpatient tempPatient = (inpatientArrayListIn.get(pivotIndex));
String pivot = tempPatient.getSurname();
int upperPointer = first;
int lowerPointer = last;
while (upperPointer < lowerPointer) {
while ((inpatientArrayListIn.get(upperPointer).getSurname().compareToIgnoreCase(pivot) <= 0) && (upperPointer < last)) {
upperPointer++;
}
while (((inpatientArrayListIn.get(lowerPointer).getSurname()).compareToIgnoreCase(pivot) > 0) && (lowerPointer > first)){
lowerPointer--;
}
if (upperPointer < lowerPointer) {
for (int i = 0; i <= inpatientArrayListIn.size(); i++) {
upperPointerValue[i] = ((inpatientArrayListIn.get(upperPointer)));
lowerPointerValue[i] = ((inpatientArrayListIn.get(lowerPointer)));
}
/* defaultTable.removeRow (upperPointer);
defaultTable.insertRow (upperPointer, lowerPointerValue);
defaultTable.removeRow (lowerPointer);
defaultTable.insertRow (lowerPointer, upperPointerValue);
*/
++upperPointer;
--lowerPointer;
}
}
if ((inpatientArrayListIn.get(lowerPointer).getSurname()).compareTo(pivot) < 0) {
for (int i = 0; i <= inpatientArrayListIn.size(); i++) {
pivotValue[i] = inpatientArrayListIn.get(pivotIndex);
lowerPointerValue[i] = (inpatientArrayListIn.get(lowerPointer));
}
/*
defaultTable.removeRow (pivotIndex);
defaultTable.insertRow (pivotIndex, lowerPointerValue);
defaultTable.removeRow (lowerPointer);
defaultTable.insertRow (lowerPointer, pivotValue);
*/
}
// Value in lowerPointer is now the pivot
if (first < (lowerPointer-1))
{
QuickSort (first, (lowerPointer-1));
}
if ((lowerPointer+1) < last)
{
QuickSort ((lowerPointer+1), last);
}
}
答案 0 :(得分:0)
在这部分中:
if (first < (lowerPointer-1))
{
QuickSort (first, (lowerPointer-1));
}
if ((lowerPointer+1) < last)
{
QuickSort ((lowerPointer+1), last);
}
您缺少第一个参数List<Inpatient> inpatientArrayListIn
,正如错误消息所描述的那样。此外,您尝试将List
用作数组,如:
upperPointerValue[i] = ((inpatientArrayListIn.get(upperPointer)));
如果我们查看List
的文档,您想要的方法是set(int index, E element)
,那么上面的内容就是:
upperPointerValue.set(i, inpatientArrayListIn.get(upperPointer));
关于你所面临的问题,编译器还没有告诉你,真的没有什么可说的了。