1 Star 0 Fork 0

20202321邬昱初/javastudy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
LinkedQueue.java 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
20202321邬昱初 提交于 3年前 . 20202321
package LBT;
public class LinkedQueue<T> implements QueueADT<T>{
private int count;
private LinearNode<T> front, rear;
public LinkedQueue()
{
count = 0;
front = rear = null;
}
public void enqueue (T element)
{
LinearNode<T> node = new LinearNode<T>(element);
if (isEmpty())
front = node;
else
rear.setNext (node);
rear = node;
count++;
}
public T dequeue() throws EmptyCollectionException
{
if (isEmpty())
throw new EmptyCollectionException ("queue");
T result = front.getElement();
front = front.getNext();
count--;
if (isEmpty())
rear = null;
return result;
}
public T first() throws EmptyCollectionException
{
if (isEmpty())
throw new EmptyCollectionException ("queue");
return front.getElement();
}
public boolean isEmpty()
{
return (count == 0);
}
public int size()
{
return count;
}
public String toString()
{
String result = "";
LinearNode<T> current = front;
while (current != null)
{
result = result + (current.getElement()).toString() + "\n";
current = current.getNext();
}
return result;
}}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wu-yuchu/javastudy.git
git@gitee.com:wu-yuchu/javastudy.git
wu-yuchu
javastudy
javastudy
master

搜索帮助