阅读下列函数说明和Java代码,将应填入(n)处的字句写在对应栏内。【说明】类Queue表示队列,类中的方法如下表所示。类Node表示队列中的元素;类EmptyQueueException给出了队列操作中的异常处理操作。public class TestMain { //主类public static viod main (String args[]){Queue q=new Queue();q.enqueue("first!");q.enqueue("second!");q.enqueue("third!");(1) {while(true)System.out.println(q.dequeue());}catch( (2) ){ }}public class Queue { //队列Node m_FirstNode;public Queue(){m_FirstNode=null;}public boolean isEmpty(){if(m_FirstNode==null)return true;else return false;}public viod enqueue(Object newNode) { //入队操作Node next=m_FirstNode;if(next==null)m_FirstNode=new Node(newNode);else{while(next.getNext()!=null)next=next.getNext();next.setNext(new node(newNode));}}public Object dequeue() (3) { //出队操作Object node;if (isEempty())(4); //队列为空, 抛出异常else{node=m_FirstNode.getObject();m_FirstNode=m_FirstNode.getNext();return node;}}}public class Node{ //队列中的元素Object m_Data;Node m_Next;public Node(Object data) {m_Data=data; m_Next=null;}public Node(Object data, Node next) {m_Data=data; m_Next=-next;}public void setObject(Object data) {m_Data=data;}public Object getObject(Object data) {return m_data;}public void setNext(Node next) {m_Next=next;}public Node getNext() {return m_Next;}}public class EmptyQueueException extends (5) { //异常处理类public EmptyQueueException() {System.out.println("队列已空! ");}}
阅读下列函数说明和Java代码,将应填入(n)处的字句写在对应栏内。
【说明】
类Queue表示队列,类中的方法如下表所示。
类Node表示队列中的元素;类EmptyQueueException给出了队列操作中的异常处理操作。
public class TestMain { //主类
public static viod main (String args[]){
Queue q=new Queue();
q.enqueue("first!");
q.enqueue("second!");
q.enqueue("third!");
(1) {
while(true)
System.out.println(q.dequeue());
}
catch( (2) ){ }
}
public class Queue { //队列
Node m_FirstNode;
public Queue(){m_FirstNode=null;}
public boolean isEmpty(){
if(m_FirstNode==null)return true;
else return false;
}
public viod enqueue(Object newNode) { //入队操作
Node next=m_FirstNode;
if(next==null)m_FirstNode=new Node(newNode);
else{
while(next.getNext()!=null)next=next.getNext();
next.setNext(new node(newNode));
}
}
public Object dequeue() (3) { //出队操作
Object node;
if (isEempty())
(4); //队列为空, 抛出异常
else{
node=m_FirstNode.getObject();
m_FirstNode=m_FirstNode.getNext();
return node;
}
}
}
public class Node{ //队列中的元素
Object m_Data;
Node m_Next;
public Node(Object data) {m_Data=data; m_Next=null;}
public Node(Object data, Node next) {m_Data=data; m_Next=-next;}
public void setObject(Object data) {m_Data=data;}
public Object getObject(Object data) {return m_data;}
public void setNext(Node next) {m_Next=next;}
public Node getNext() {return m_Next;}
}
public class EmptyQueueException extends (5) { //异常处理类
public EmptyQueueException() {
System.out.println("队列已空! ");
}
}