#ifndef LISTTEMP_H #define LISTTEMP_H #define NULL 0 template class ListTemp { private: struct Node { T data; Node *next; }; Node *head; int size; public: ListTemp(); ~ListTemp(); int getLength() const; bool isEmpty() const; void AddHead(const T& newData); //************************declaration of the inner iterator class**************************** class Iterator { friend class ListTemp; //friend class private: Node *curr; Iterator(Node *ptr); //constructor with Node parameter, defined as private public: Iterator(); //default constructor Iterator operator++(int); //post-increment of ++ T& operator*() const; bool operator==(const Iterator other) const; };//class Iterator Iterator Begin() const; Iterator End() const; }; //************************implementation of the iterator inner class************************** template ListTemp::Iterator::Iterator() { curr = NULL; } template ListTemp::Iterator::Iterator(Node *ptr) { curr = ptr; } template typename ListTemp::Iterator ListTemp::Iterator::operator++(int) { Iterator temp = *this; this->curr = curr->next; return temp; } template T& ListTemp::Iterator::operator*() const { return curr->data; } template bool ListTemp::Iterator::operator==(const Iterator other) const { return curr == other.curr; } //************************implementation of the Begin and End position************************** template typename ListTemp::Iterator ListTemp::Begin() const { return Iterator(head); //private of Iterator class } template typename ListTemp::Iterator ListTemp::End() const { return Iterator(); } //************************implementation of the linked list class template************************** template ListTemp::ListTemp() { head = NULL; size = 0; } template ListTemp::~ListTemp() { Node *current = head; Node *temp = NULL; while (current != NULL) { temp = current; current = current->next; delete temp; } } template int ListTemp::getLength() const { return size; } template bool ListTemp::isEmpty() const { return size == 0; } template void ListTemp::AddHead(const T& newData) { Node *temp = new Node; temp->next = head; temp->data = newData; head = temp; size++; } #endif