Veom wrote:
Thanks ratfink, heres the kicker. The header file has been provided for us and we cannot modify any of the methods or variables in the class we can only use what is provided. SO adding static methods and such i don't think is allowed. The reason it is all implemented in the header file is because it is a template you need to implement templates in the header because of a C++ "feature".
Ah good point, I forgot about it being a template. Stupid C++ compilers make things so hard (C# (or any modern language) ftw).
I'm not sure how you're supposed to be able to initialise fLeftmost and fRightmost without calling another method to find them from aList. Does DoubleLinkedNode<T> have a method that does the search operation for you (I hope not; that responsibility should be the iterator's)? Is there another method on the iterator that iterates through a node forward (or back) to the start (or end) that I'm not seeing?
Frankly, I don't really understand the iterator structure you've got going here. The iterators I'm used to in C# are not immutable like this one seems to be (the fCurrent is const, and begin and end return ostensibly a new NodeIterator<DataType> instance, since they're const methods). But okay, let's say you're doing iterators in an immutable fashion and moving next with ++. Why do you need to store the fLeftmost and fRightmost... surely whether you're on the first or last node is self evident by looking at fCurrent.pPreviousNode (or whatever you've called it) and fCurrent.pNextNode and seeing if they're NULL. I guess it'd give you the ability to jump to the start or end of the list in an O(1) fashion, but the first and last nodes of a linked list should be stored by the LinkedList class (assuming you have one; I hope you do) and if you want to jump to the start or end, I think you should ask for a new iterator at those positions from the linked list class not from another iterator.
What I'm getting at is this is either an odd way of doing a LinkedList that I'm not familiar with, so I might be missing some esoteric way of solving this, or there's a bug in your assignment. Can you go ask your tutor or something?
I also just tried in my compiler (VS2010)
not using static methods, just to make sure I'm not talking shit (it's been a long time since I wrote C++), turns out you can actually do it, but from what
I'm reading you're not supposed to because its evil. Just an FYI. Typical horrible C++ letting you shoot yourself in the foot, I guess.