Grea, you seem to miss the point of iterators.
Iterators are an interface for the container, so that you can use the same algorithm for different containers.
For instance let's say you want to write a "universal"
print_contents() function.
If you write it as a function template, like...
1 2 3 4 5 6 7 8
|
template <typename Iterator>
void print_contents(Iterator b, Iterator e)
{
for (; b != e; ++b)
std::cout << *b << ' ';
std::cout << std::endl;
}
|
... then you can use it with any container that supplies C++ style
begin and
one-past-end iterators.
So iterators provide an external interface. Instead you make things harder for yourself by overusing iterators, internally.
In addition, I noticed some typos which seem to go undetected (because of templates?) and a fishy practice of
include'ing
.cpp files -- at least give them another extension, such as
.inc so that other programmers and IDE's not get confused.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
template <typename Element>
const Element & Iterator<Element>::getNext() const
{
return next->vlaue;
}
template <typename Element>
Element & Iterator<Element>::getPrevious()
{
return prev->vale;
}
template <typename Element>
const Element & Iterator<Element>::getPrevious() const
{
return prev->vale;
}
|
Then your
Iterator::insert() function, which in my opinion has no right to exist in the first place, seems to only care about the previous and next nodes, ignoring the current node. Since perhaps this is a misunderstanding on my part, I won't comment further.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
template <typename Element>
void Iterator<Element>::insert(const Element &e)
{
Node<Element> *newNode = new Node<Element>(e);
newNode->prev = prev;
newNode->next = next;
if(list.first ==NULL)
list.first = list.last = newNode;
else if(prev != NULL)
prev->next = newNode;
else
next->prev = newNode;
next = newNode;
++list.size;
}
|
Hopefully other members can help you more than I, because for me the code is too difficult to follow.