1

我的代码如下。它是项目中包含的一种排序方法,而不是冒泡排序,以提高代码效率。我的问题是我不断收到以下错误:

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);

        }

    }
4

1 回答 1

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));

对于编译器尚未告诉您的您所面临的问题,真的没有太多可以说的了。

于 2013-02-15T19:58:18.090 回答