代码拉取完成,页面将自动刷新
package wek3;
import wek1.EmptyCollectionException;
import wek1.LinearNode;
public class LinkedQueue<T> implements QueueADT<T>
{
private int count;
private LinearNode<T> head, tail;
/**
* Creates an empty queue.
*/
public LinkedQueue()
{
count = 0;
head = tail = null;
}
@Override
public void enqueue(T element)
{
LinearNode<T> node = new LinearNode<T>(element);
if (isEmpty()) {
head = node;
} else {
tail.setNext(node);
}
tail = node;
count++;
}
@Override
public T dequeue() throws EmptyCollectionException
{
if (isEmpty()) {
throw new EmptyCollectionException("queue");
}
T result = head.getElement();
head = head.getNext();
count--;
if (isEmpty()) {
tail = null;
}
return result;
}
@Override
public T first() throws EmptyCollectionException
{
if (isEmpty()) {
throw new EmptyCollectionException("wrong");
}
T result = head.getElement();
return result;
}
@Override
public boolean isEmpty()
{
if (size() == 0) {
return true;
} else {
return false;
}
}
@Override
public int size()
{
return count;
}
@Override
public String toString()
{
LinearNode node;
String result="";
node = head;
for(int a=0;a<count ;a++){
result += node.getElement()+ " ";
node = node.getNext();
}
return result;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。