我的代码如下。它是项目中包含的一种排序方法,而不是冒泡排序,以提高代码效率。我的问题是我不断收到以下错误:
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);
}
}