#pragma once #include "List.h" template size_t List::size() { return this->length; } template void List::push_back(T & el) { ListLink * link = new ListLink { .prev = this->head, .next = nullptr, .value = el, }; if (this->head != nullptr) this->head->next = link; if (this->head == nullptr) this->tail = link; this->head = link; this->length++; } template void List::remove(const T & target) { ListLink * link = nullptr; for (link = this->tail; link != nullptr; link = link->next) { if (link->value == target) break; } if (link == nullptr) return; // target not in list if (link->next != nullptr) link->next->prev = link->prev; if (link->prev != nullptr) link->prev->next = link->next; delete link; this->length--; } template void List::pop_back() { if (this->head == nullptr) return; // empty list ListLink * secondlast = this->head->prev; if (secondlast != nullptr) secondlast->next = nullptr; delete this->head; if (this->tail == this->head) this->tail = nullptr; this->head = secondlast; this->length--; } template void List::clear() { ListLink * link = this->tail; while (link != nullptr) { ListLink * next = link->next; delete link; link = next; } this->head = nullptr; this->tail = nullptr; this->length = 0; } template T & List::operator [] (size_t index) { ListLink * link = this->tail; for (size_t i = 0; i < index; i++) link = link->next; return link->value; } template ListRange List::range() { return { *this }; } template ListIterator List::begin() { return this->range().begin(); } template ListIterator List::end() { return this->range().end(); }