I've made a linkedlist out of nodes in which I store some items. I've also created an iterator, though the remove function of the iterator doesn't work as intended.
That's my linkedlist
That's the node class
That's the code of the iterator so far but I can't really get the remove method to work. When I create a list and iterate through it, I can never remove the first item from the list. Is it the next() method I should change or is the error in the remove() method?
I'd very much appreciate any input on this!
Let us say you have a LinkedList containing three nodes, a, b, and c.
Now you want to remove the node b using an iterator. As per your remove logic,
you would nullify b. But does it change what a's next is pointing to?
Further if it is the a node you wanted to remove, shouldn't the
reference of first be updated?
How about you write down the intended logic of your removemethod
in plain english first and then turn it into Java instructions?
posted 7 years ago
I mean referring to, not pointing to, in the last line of first para of my response.
My cell phone's scroll options are not very good. Hence the poor formatting.