📄 arrayqueue2.java
字号:
public class ArrayQueue2 implements Queue
{
public static final int CAPACITY = 1000;
private int N, f, r;
private Object Q[];
private int _size;
public ArrayQueue2()
{
this(CAPACITY);
}
public ArrayQueue2(int cap)
{
N = cap;
Q = new Object[N];
f= 0;
r = 0;
_size = 0;
}
public int size()
{
return _size;
}
public boolean isEmpty()
{
return (_size==0);
}
public Object front() //throws StackFullException
{
if (isEmpty())
//throw new StackFullException("Stack overflow.");
{
return ("Queue is empty.");
}
return Q[f];
}
public Object dequeue()// throws StackEmptyException
{
if (isEmpty())
{
return ("Queue is empty.");
}
//throw new StackEmptyException("Stack is empty.");
Object temp = Q[f];
Q[f]= null;
f = (f+1)%N;
_size -=1;
return temp;
}
public Object enqueue(Object o)// throws StackEmptyException
{
if (size()==(N))
{
return ("Queue is full.");
}
// throw new StackEmptyException("Stack is Empty.");
Q[r] = o;
r= (r+1)%N;
_size +=1;
return ("-");
}
public String getContent()
{
String cont= "";
System.out.println("f="+f);
System.out.println("r="+r);
if (isEmpty())
return cont;
for (int i =f; i<(f+_size); i++ )
{
cont += (Q[i%N].toString()+ ",");
}
return (cont.substring(0,cont.length()-1));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -