public Iterator<Item> iterator(){
return new ArrayIterator();
}
private class ArrayIterator implements Iterator<Item>{
private int[] random;
private int current = 0; //line: 47
random = new int[N];
for(int i = 0; i < N; i++)
random[i] = head + i;
StdRandom.shuffle(random);
public boolean hasNext(){ //line:52
return current != (N - 1);
}
public void remove(){ }
public Item next(){
return RQ[random[current++]];
}
}
错误报告
File: C:\Users\CHN\algs4\RandomizedQueue.java [line: 47]
Error: Syntax error on token ";", { expected after this token
File: C:\Users\CHN\algs4\RandomizedQueue.java [line: 52]
Error: Syntax error, insert "VariableDeclarators" to complete LocalVariableDeclaration
File: C:\Users\CHN\algs4\RandomizedQueue.java [line: 52]
Error: Syntax error, insert ";" to complete LocalVariableDeclarationStatement
File: C:\Users\CHN\algs4\RandomizedQueue.java [line: 52]
Error: Syntax error on token "{", ; expected
总报告缺分号、花括号之类的
但像这样的又可以( 不是同一个类里的):
public Iterator iterator(){
return new ListIterator();
}
private class ListIterator implements Iterator{
private Node current = first;
public boolean hasNext(){
return current != null;
}
public void remove(){ }
public Item next(){
Item item = current.item;
current = current.next;
return item;
}
}
对java一知半解,求解答,谢谢。