public class PlaneDemo
{
public static void main(String args[])
{
ArrayQueue<Plane> q = new ArrayQueue<Plane>();
Plane p1 = new Plane("Aircraft 1", 3);
Plane p2 = new Plane("Aircraft 2", 1);
Plane p3 = new Plane("Aircraft 3", 2);
q.addQueue(p1);
q.addQueue(p2);
q.addQueue(p3);
while(!q.isEmptyQueue())
{
System.out.println("Vehicle: ");
System.out.println(q.front());
q.deleteQueue();
}
}
}
cannot find symbol q.addQueue(p1); ^ symbol: method addQueue(Plane) location: variable q of type ArrayQueue<Plane> error: cannot find symbol q.addQueue(p2); ^ symbol: method addQueue(Plane) location: variable q of type ArrayQueue<Plane>
我喜欢恐慌,这很快就要到了,我无法弄清楚我做错了什么。
public class ArrayQueue<T>
{
private int maxQueueSize;
private int count;
private int queueFront;
private int queueRear;
private T[] list;
public ArrayQueue()
{
maxQueueSize = 100;
queueFront = 0;
queueRear = maxQueueSize - 1;
count = 0;
list = (T[]) new Object[maxQueueSize];
}
public ArrayQueue(int queueSize)
{
if(queueSize <= 0)
{
System.err.println("Array size must be a positive number. Creating array at default size of 100.");
maxQueueSize = 100;
}
else
maxQueueSize = queueSize;
queueFront = 0;
queueRear = maxQueueSize - 1;
count = 0;
list = (T[]) new Object[maxQueueSize];
}
public void initializeQueue()
{
for(int i = queueFront; i < queueRear; i = (i + 1) % maxQueueSize)
list[i] = null;
queueFront = 0;
queueRear = maxQueueSize - 1;
count = 0;
}
public boolean isEmptyQueue()
{
return(count == 0);
}
public boolean isFullQueue()
{
return(count == maxQueueSize);
}
public T peek() //throws QueueUnderflowException
{
/*if(isEmptyQueue())
throw new QueueUnderflowException();*/
return (T) list[queueFront];
}
/*public T back() throws QueueOverflowException
{
if(isFullQueue())
throw new QueueUnderflowException();
return (T) list[queueRear];
}
*/
public void enqueue(T queueElement) throws QueueOverflowException
{
if(isFullQueue())
throw new QueueOverflowException();
queueRear = (queueRear + 1) % maxQueueSize;
count++;
list[queueRear] = queueElement;
}
public void dequeue() throws QueueUnderflowException
{
if(isEmptyQueue())
throw new QueueUnderflowException();
count--;
list[queueFront] = null;
queueFront = (queueFront + 1) % maxQueueSize;
}
}
答案 0 :(得分:0)
替换此
getpath($p[0:-1])
对于这个q.addQueue(p1);
q.addQueue(p2);
q.addQueue(p3);
因为是唯一的方法,你必须向类中添加一个元素
q.enqueue(p1); etc