asked 94.4k views
0 votes
eate a class which is an iterator for the LinkedCollection. This class must implement the Iterator interface. You must think about what field(s) you need to keep track of the current element in the iteration, how to initialize the field(s), how to move to the next element, and how to know when all elements have been returned.

1 Answer

2 votes

Answer:

class CustomDataStructure implements Iterable<> {

// code for data structure

public Iterator<> iterator() {

return new CustomIterator<>(this);

}

}

class CustomIterator<> implements Iterator<> {

// constructor

CustomIterator<>(CustomDataStructure obj) {

// initialize cursor

}

// Checks if the next element exists

public boolean has Next() {

}

answered
User Pranav Raj
by
7.8k points
Welcome to Qamnty — a place to ask, share, and grow together. Join our community and get real answers from real people.