Java:队列未显示所有记录

时间:2023-01-05 07:18:10

I am trying to add patient records into a queue and then display all the records on the screen but I am not getting them.. I guess the display method isn't working for me.. I probably made a mistake.. Here is my code for queue of the patients.

我正在尝试将患者记录添加到队列中,然后在屏幕上显示所有记录但我没有得到它们......我猜显示方法对我不起作用..我可能犯了一个错误..这是我的患者队列的代码。

public class Patient_Queue {

    private LinkedList list;

    public Patient_Queue()
    {
        // Create a new LinkedList.
        list= new LinkedList();
    }

    public boolean isEmpty()
    {
        return (list.size() == 0);
    }

    public void joinQueue(Object item)
    {
        list.add(item);
    }

    public Object Consultation()
    {
        Object item = list;
        list.remove(0);
        return item;
    }

    public void display() {
        for(int q=0;q<list.size();q++)
        {
            System.out.println(list.get(q));
        }
    }

    public int size(){
        return list.size();
    }

    public void clear()
    {
        list.clear();
    }
}

1 个解决方案

#1


1  

It seems to be a mistake here:

这似乎是一个错误:

public Object Consultation()
{

    Object item = list;

    list.remove(0);

    return item;
}

Corrected version:

public Object Consultation()
{

    Object item = list.get(0); // fix

    list.remove(0);

    return item;
}

Note that LinkedList implements Queue interface and you can use its Queue methods directly.

请注意,LinkedList实现了Queue接口,您可以直接使用其Queue方法。

#1


1  

It seems to be a mistake here:

这似乎是一个错误:

public Object Consultation()
{

    Object item = list;

    list.remove(0);

    return item;
}

Corrected version:

public Object Consultation()
{

    Object item = list.get(0); // fix

    list.remove(0);

    return item;
}

Note that LinkedList implements Queue interface and you can use its Queue methods directly.

请注意,LinkedList实现了Queue接口,您可以直接使用其Queue方法。