-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeList.java
More file actions
38 lines (28 loc) · 928 Bytes
/
NodeList.java
File metadata and controls
38 lines (28 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.util.LinkedList;
import java.util.Queue;
import java.util.Iterator;
/*This class provides an iterator over the nodes in a list.*/
public class NodeList<T extends Comparable<T>, S extends Comparable<S>>
implements Iterator<Node<T,S>> {
private Queue<Node<T,S>> elements = new LinkedList<Node<T,S>>();
public NodeList(Node<T,S> startNode) {
if (startNode == null) {
return;
}
Node<T,S> currentNode = startNode;
do {
elements.add(currentNode);
currentNode = currentNode.getNodeNext();
} while (startNode != currentNode);
}
public boolean hasNext() {
return elements.peek() != null;
}
public Node<T,S> next() {
return elements.poll();
}
public void remove() {
throw new UnsupportedOperationException(
"Remove for Node List has not implemented");
}
}