1

I get an error when I try return new MyIterator() and I'm not sure what to do with the MyIterator constructor (have to define iterator based on a start node parameter). Any idea how to fix this? I know how to implement the next and hasNext.

I think I solved it....Thanks!!

1
  • 2
    Provide it with the start node..? Commented Mar 10, 2012 at 20:41

1 Answer 1

2

You're defining a single constructor for your iterator, MyIterator(MyListNode<E> start). From your code, it's clear that the MyListNode<E> start argument is missing.

What I mean is, in this line:

return new MyIterator();

... you need to pass a reference to the first node in the list, something like this:

return new MyIterator(firstNode);  // replace firstNode with the actual value
Sign up to request clarification or add additional context in comments.

2 Comments

I have not written code in the constructor....I do not know what to do with it. What do I do with the parameter...
When you call return new MyIterator(); you MUST pass as an argument a reference to the first node of the list, because that's how you defined the constructor. What to do with the first node, inside the Iterator? that's a different question. Hint: you need to store it in an attribute and make sure to implement hasNext and next accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.