Might be because you have defined "mylist" as a ListI interface type and written "implements Iterable" in the LinkedList class definition rather than the ListI interface definition. For the compiler to know that your ListI interface is capable of for-each loop, you have to extend the ListI interface with Iterable interface like the following: public interface ListI extends Iterable {.....
The naming of hasNext() and next() is very confusing. By definition, hasNext() "returns true if the iteration has more elements.", however it returns true if the current node is the last one which have no more elements following it...And next() method actually returns the current node instead of the next node...
hasNext( ) tells if you can keep moving forward. That is the case even at the last node because in that instance you have a pointer that goes to null. next( ) is the function that actually moves the pointer forward after returning the value it was just in. In other words, you can move forward at the last node even if you land on null so hasNext returns true and next moves forward to null, when in null you can't go anywhere so hasNext returns false and the process stops.
hasNext() is just saying if there is more item to move to besides the first node. Next() is moving the point to the the next element if there are more element
This was probably the most succinct explanation of Iterators I have seen online. Thank you for putting these lectures online.
Thank you for the wonderful series of videos. Have a question though, does the series miss Stacks and Queue 1 and 2 videos?
Amazing.thank you Professor for making the world a better place
You write letters backward and from right to left???? That just blew my mind....
lol, thought the same thing so I checked into it. He's not, it's the high tech glass he's using www.learning.glass/
lol he just applies mirror effect to the whole video when editing at last
in the hasNext() method .. if i said return (index.next != null) , is that also considered right?
if index is pointed to head, then null pointer exception
why foreach(int x:mylist) don't work even after implementing Iteratorhelper class?
Might be because you have defined "mylist" as a ListI interface type and written "implements Iterable" in the LinkedList class definition rather than the ListI interface definition.
For the compiler to know that your ListI interface is capable of for-each loop, you have to extend the ListI interface with Iterable interface like the following:
public interface ListI extends Iterable {.....
The naming of hasNext() and next() is very confusing. By definition, hasNext() "returns true if the iteration has more elements.", however it returns true if the current node is the last one which have no more elements following it...And next() method actually returns the current node instead of the next node...
I agree, I was wondering the same thing.
Yea, I'm confused with that part too, Can anyone please explain it?
hasNext( ) tells if you can keep moving forward. That is the case even at the last node because in that instance you have a pointer that goes to null. next( ) is the function that actually moves the pointer forward after returning the value it was just in. In other words, you can move forward at the last node even if you land on null so hasNext returns true and next moves forward to null, when in null you can't go anywhere so hasNext returns false and the process stops.
hasNext() is just saying if there is more item to move to besides the first node. Next() is moving the point to the the next element if there are more element