我的项目要求我使用列表创建一个FIFO队列,我必须创建简单的方法来放置,删除和返回对象等。但是当我编译以下代码时:
import java.io.PrintStream;
import java.util.NoSuchElementException;
class IntQueueImpl {
public int size;
private Node head, tail;
private class Node {
int item;
Node next;
Node(int item) {
this.item = item;
next = null; }
}
IntQueueImpl(int max) {
head = null; tail = null;
}
public boolean isEmpty() {
return (head == null);
}
public void put(int item) {
Node t = tail;
tail = new Node(item);
if (isEmpty()) head = tail;
else t.next = tail;
size++;
}
public int get() throws NoSuchElementException;{
if ( isEmpty() )
throw new NoSuchElementException();
int v = head.item;
Node t = head.next;
head = t;
return v;
}
public int peek() throws NoSuchElementException{
if ( isEmpty() ){
throw new NoSuchElementException();
}
int peekelement =head.item;
return peekelement;
}
public int size(){
if(isEmpty()) return 0;
else return size;
}
}
它给了我以下错误:
IntQueueImpl.java:35: error: missing method body, or declare abstract
public int get() throws NoSuchElementException;{
^
IntQueueImpl.java:41: error: return outside method
return v;
我必须弄清楚它意味着什么或如何解决它....
答案 0 :(得分:1)
在第34行,你有:
public int get() throws NoSuchElementException;{
删除该分号,看看是否修复了编译器错误:
public int get() throws NoSuchElementException {
答案 1 :(得分:1)
如何删除&#39 ;;&#39 ;?在public" int get()抛出NoSuchElementException; {"