📄 sequencequeue.java
字号:
public class SequenceQueue implements Queue
{
Object Entry[];
int size;
int maxSize;
static final int MAX = 20;
public SequenceQueue()
{
Entry = new Object[MAX];
size = 0;
maxSize = MAX;
}
public SequenceQueue(int s)
{
Entry = new Object[s];
size = 0;
maxSize = s;
}
public void enqueue (Object element) //入队
{
if(size < maxSize)
{
Entry[size] = element;
size++;
}
else
System.out.println("Queue is full,sorry! ");
}
public Object dequeue() throws EmptyQueueException//出队
{
Object result = Entry[0];
if(size > 0)
{
for(int index = 0; index < size-1; index++)
{
Entry[index] = Entry[index+1];
}
size--;
}
else
throw new EmptyQueueException();
return result;
}
public void display()
{
for(int index = 0; index < size; index++)
System.out.print(" "+Entry[index]);
System.out.print("\n");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -