#pragma once template class Node { private: E content; Node *nextNode; public: Node(); Node(E _content, Node *_nextNode = NULL); ~Node(); // Returns a reference to the content. E &getContent(); // Returns a reference to the next Node. May return NULL if this Node is the // last one. Node *getNextPtr(); // Set the next Node _nextNode. Returns original pointer. Node *setNext(Node *_nextNode); // Returns a reference to the Tail. Node &getTail(); // Returns a reference to the Node of given index. Node &getByIndex(const int index); // Compare the content with the argument. bool operator==(const E &other); // Destructs the Node itself and all the node behind it. void destruct(); }; template class Iterator { private: Node *current; public: Iterator(Node *pos); bool hasNext(); // Return the same as hasNext(); operator bool(); E &next(); }; template Node::Node() : content(0), nextNode(NULL){}; template Node::Node(E _content, Node *_nextNode) : content(_content), nextNode(_nextNode){}; template Node::~Node(){}; template E &Node::getContent() { return this->content; } template Node *Node::getNextPtr() { return this->nextNode; } template Node *Node::setNext(Node *_nextNode) { Node *temp = this->nextNode; this->nextNode = _nextNode; return temp; } template Node &Node::getTail() { if (this->nextNode == NULL) { return *this; } return this->nextNode->getTail(); } template Node &Node::getByIndex(const int index) { if (index == 0) { return *this; } return this->nextNode->getByIndex(index - 1); } template bool Node::operator==(const E &other) { return this->content == other; } template void Node::destruct() { if (this->nextNode != NULL) { this->nextNode->destruct(); } delete this; } template Iterator::Iterator(Node *start) : current(start){}; template bool Iterator::hasNext() { return this->current != NULL; } template Iterator::operator bool() { return this->hasNext(); } template E &Iterator::next() { if (!this->hasNext()) { throw(IndexError("Out of bound!")); } E &temp = this->current->getContent(); this->current = this->current->getNextPtr(); return temp; }