-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListIterator.java
More file actions
37 lines (33 loc) · 1.06 KB
/
ListIterator.java
File metadata and controls
37 lines (33 loc) · 1.06 KB
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
37
package MMS;
/*
Assignment number :10
File Name : ListIterator.java
Name: Ran Zaaroor
Student ID : 209374040
Email : Ran.zaaroor@gmail.com
*/
/**
* Represents an iterator of a linked list of memory blocks.
* <br> (Part of Homework 10 in the Intro to CS course, Efi Arazi School of CS)
*/
public class ListIterator {
// Current position in the list (cursor)
public Node current;
/** Constructs a list iterator, starting at the given node */
public ListIterator(Node node) {
current = node;
}
/** Checks if this iterator has more elements to process */
public boolean hasNext() {
return (current != null);
}
/** Returns the next memory block in the list, and advances the cursor position.
* This method may be called repeatedly, to iterate through the list.
* @return the memory block at the cursor's location
*/
public MemBlock next() {
Node currentNode = current;
current = current.next;
return currentNode.block;
}
}