This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a minheap class that is implemented as a priorityqueue and it works fine as far as to the iterator that I have to implement as a innerclass. But I can't get it to work properly.
Here is part of the code:
I see two things very wrong with the iterator right off the bat. One is that "a" is never initialized to point to anything. It will always be null, so your iterator will fail trying to access its elements with a NullPointerException.
The other one is that if this is a heap-based container, then the iterator should be calling fixup/fixdown methods as it extracts the elements, to reform the heap -- either the original (if iteration is destructive) or a copy (if it's not).
You don't really tell us where things fail, so I don't know which of these things you're worried about -- or perhaps there are even others.
Thank you for answering and I will add code tags this time. Hopefully it works.
Back to my problem: Yes, it is correct that a is null. I do get NPE in the hasNext method and myListIterator gives an NPE. And now I understand that a is never initialized. But how do I do that?
Eclipse doesn't take this:
Eclipse says: cannot create a generic array out of MinHeap.HeapEntry<E>.