iterator를 확장하고 두 개의 메서드를 추가하는 LLIterator라는 인터페이스를 만들었습니다.이 클래스를 사용하려고 할 때 컴파일 할 수 없었습니다. 여기에 내가 가진 것이있다. 내 사용자 인터페이스는 다음과 같이이다 :내 인터페이스에서 메서드를 찾을 수 없습니다.
import java.util.Iterator;
public interface LLIterator<T> extends Iterator<T>{
boolean hasNext();
T next();
void remove();
void addBefore(T element);
void addAfter(T element);
}
내 LinkedList의이 같은 수 있습니다 : 다른 클래스에서
import java.lang.StringBuilder;
import java.util.NoSuchElementException;
import java.util.Iterator;
import java.util.ArrayList;
/**
* A class to represent a linked list of nodes.
*/
public class LinkedList<T> implements Iterable<T>{
/** the first node of the list, or null if the list is empty */
private LLNode<T> first;
/** some codes here
@Override
public LLIterator<T> iterator() {
return new LinkedListIterator();
}
private class LinkedListIterator implements LLIterator<T>{
LLNode<T> nodeptr = first;
final LinkedList<T> list = getList();
@Override
public void addBefore(T element){
if(nodeptr == first || list.isEmpty()){
throw new NoSuchElementException();
}
LLNode<T> newnode = new LLNode<T>(element, null);
newnode.setNext(nodeptr);
}
@Override
public void addAfter(T element){
LLNode<T> newnode;
if(nodeptr == first || list.isEmpty()){
newnode = new LLNode<T>(element, null);
list.setFirst(newnode);
}
newnode = new LLNode<T>(element, null);
newnode.setNext(nodeptr.getNext());
nodeptr.setNext(newnode);
}
}
, 나는 그것을 컴파일하지만 때이 Linkedlist
의 반복자 방법을 사용 addBefore
방법이라고 , 여기
cannot find symbol
symbol: method addAfter(WordData)
location: variable iterator of type java.util.Iterator<WordData>
을 보여줍니다 내 다른 클래스의 일부입니다
public void addFollowingWord(String word){
Iterator<WordData> iterator = list.iterator();
WordData current = iterator.next();
while(iterator.hasNext()){
if(current.getWord().equals(word)){
current.incrementCount();
}
else if(current.getWord().compareTo(word) < 0){
current = iterator.next();
}
else if(current.getWord().compareTo(word) > 0){
WordData newword = new WordData(word);
iterator.addBefore(newword);
}
}
if(!iterator.hasNext()){
WordData newword = new WordData(word);
iterator.addAfter(newword);
}
}
매우 혼란 스럽습니다. 어딘가에서 실수를 했습니까?
는 PLZ를 살펴 클래스 – firephil
의 전체 코드를 게시 – Rio