#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; private: Node *head; Node *curr; Iterator(Node *hear_ptr, Node *curr_ptr); //constructor with Node parameter, defined as private public: Iterator(); //default constructor Iterator operator++(int); //post-increment of ++ //please implement this Iterator operator--(int); //post-decrement of -- T& operator*() const; bool operator==(const Iterator other) const; };//class Iterator //please implement this Iterator Begin() const; //please implement this Iterator End() const; }; //************************implementation of the iterator inner class************************** template ListTemp::Iterator::Iterator() { head = NULL; curr = NULL; } template ListTemp::Iterator::Iterator(Node *head_ptr, Node *curr_ptr) { head = head_ptr; curr = curr_ptr; } template typename ListTemp::Iterator ListTemp::Iterator::operator++(int) { Iterator temp = *this; this->curr = curr->next; return temp; } // please implement this template typename ListTemp::Iterator ListTemp::Iterator::operator--(int) { Iterator temp = *this; for (Iterator itr(head,head); !(itr == *this); itr++) { if ((itr.curr)->next == this->curr) { this->curr = itr.curr; 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(this->head,this->head); } template typename ListTemp::Iterator ListTemp::End() const { return Iterator(this->head,nullptr); } //************************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