📄 queue.java
字号:
public class Queue
{
private class Node
{
private String item;
private Node link;
public Node( )
{
item = null;
link = null;
}
public Node(String newItem, Node linkValue)
{
item = newItem;
link = linkValue;
}
}//End of Node inner class
private Node front;
private Node back;
public Queue( )
{
front = null;
back = null;
}
/**
Adds a String to the back of the queue.
*/
public void addToBack(String itemName)
{
Node newEntry =
new Node(itemName, null);
if (front == null) //empty queue
{
back = newEntry;
front = back;
}
else
{
back.link = newEntry;
back = back.link;
}
}
public boolean isEmpty( )
{
return (front == null);
}
public void clear( )
{
front = null;
back = null;
}
/**
Returns the String in the front of the queue.
Returns null if queue is empty.
*/
public String whoIsNext( )
{
if (front == null)
return null;
else
return front.item;
}
/**
Removes a String from the front of the queue.
Returns false if the list is empty.
*/
public boolean removeFront( )
{
if (front != null)
{
front = front.link;
return true;
}
else
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -