forked from erasmuss22/Music-Player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinkedSetIterator.java
57 lines (51 loc) · 1.38 KB
/
LinkedSetIterator.java
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
///////////////////////////////////////////////////////////////////////////////
// ALL STUDENTS COMPLETE THESE SECTIONS
// Main Class File: Browser.java
// File: LinkedSetIterator.java
// Semester: Spring 2011
//
// Author: Erin Rasmussen ejrasmussen2@wisc.edu
// CS Login: rasmusse
// Lecturer's Name: Beck Hasti
// Lab Section: Lecture 2
//
//
//////////////////////////// 80 columns wide //////////////////////////////////
import java.util.*;
/**
* Implementation of the {@link Iterator} interface for use with
* {@link LinkedSet}.
* <p>
* <strong>Modify this class to implement the required {@link Iterator} methods
* along with any constructors, fields, or other methods you feel are
* necessary.</strong>
*
* @author Ben Liblit
* @param <E>
* the type of data stored in the list
*/
public class LinkedSetIterator<E> implements Iterator<E> {
private DoubleListnode<E> curr;
private DoubleListnode<E> prev;
LinkedSetIterator(DoubleListnode<E> head){
curr = head;
}
@Override
public boolean hasNext() {
return curr != null;
}
public E next() {
if (!hasNext()){
throw new NoSuchElementException();
}
E stuff = curr.getData();
prev = curr;
curr = curr.getNext();
return stuff;
}
public void remove() {
prev = prev.getPrev();
prev.setNext(curr);
curr.setPrev(prev);
}
}