queueclass.java

来自「java小程序」· Java 代码 · 共 45 行

JAVA
45
字号
class QueueClass implements QueueInterface
{
private int head;
private int tail;
private Man queue[];
public QueueClass()
{
head=tail=0;
queue= new Man[4];
}
public boolean isEmpty()
{
return (head==tail)?true:false;
}
public void addTail(String name)
{
if((tail)%queue.length==head)
System.out.printf("队列满了"+name+"无法加入");
else queue[(tail++)%queue.length]=new Man(name);
}
public Man removeHead()
{
if(isEmpty())
{
System.out.printf("队列空白");
return new Man(" ");
}
head=(head+1)%queue.length;
return queue[head];
}
public void show()
{
int p=head;
System.out.print("显示队列");
while(p!=tail)
{
p=(p+1)%queue.length;
System.out.print(queue[p].getName()+" ");
}
System.out.println();
}
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?