标签:队列 数据 turn war nts time add exce bool
public class MyQueue {
int[] elements;
public MyQueue()
{
elements = new int[0];
}
//入队
public void add(int element)
{
int[] newArr = new int[elements.length+1];
for(int i = 0;i < elements.length;i++)
{
newArr[i] = elements[i];
}
newArr[elements.length] = element;
elements = newArr;
}
//出队
public int poll()
{
if(elements.length == 0)
{
throw new RuntimeException("Queue is empty");
}
int[] newArr = new int[elements.length-1];
int elemment = elements[0];
for(int i = 1;i < elements.length;i++)
{
newArr[i-1] = elements[i];
}
elements = newArr;
return elemment;
}
//判断队列是否为空
public boolean isEmpty()
{
return elements.length == 0;
}
}
标签:队列 数据 turn war nts time add exce bool
原文地址:https://www.cnblogs.com/baoyingying/p/11794014.html