#pragma once #include "allocators.h" namespace tp { extern ModuleManifest gModuleContainer; template class Queue { public: template class Node { public: Node* below; NodeType data; public: Node(NodeType data, Node* below) { this->below = below; this->data = data; } }; template struct Iterator { Node* mIter; IterType& operator->() { return mIter->data; } IterType& data() { return mIter->data; } const Iterator& operator*() { return *this; } inline void operator++() { mIter = mIter->below; } bool operator==(const Iterator& end) { return mIter == NULL; } bool operator!=(const Iterator& end) { return mIter != NULL; } }; alni length; Node* top; Node* bottom; Queue() { MODULE_SANITY_CHECK(gModuleContainer); length = 0; top = nullptr; bottom = nullptr; } ~Queue() { free(); } // pushes the node on the bottom of the stack void push(Type data) { Node* new_node = new Node(data, NULL); if (bottom) { bottom->below = new_node; } else { top = new_node; } bottom = new_node; length++; } // pops the top node of the stack void pop() { assert(top); Node* del = top; top = top->below; delete del; length--; if (!top) { bottom = NULL; } } // deletes all nodes void free() { Node* del = top; for (alni i = 0; i < length; i++) { Node* below = del->below; delete del; del = below; } length = 0; top = NULL; bottom = NULL; } alni sizeAllocatedMem() { alni out = 0; out += sizeof(Node*) * 2; out += sizeof(alni); out += sizeof(Node) * length; return out; } alni sizeUsedMem() { return sizeAllocatedMem(); } Iterator begin() const { return {top}; } Iterator end() const { return {}; } }; };