#include #include "Node.h" class Chain { public: void* start; void* end; Chain() { start = nullptr; end = nullptr; } bool isNull() const { return start == nullptr; } template void add(T value) { if(start==nullptr) { Node tstart(value); start = &tstart; end = &tstart; return; } Node node(value, static_cast*>(end)); static_cast*>(end)->next = &node; end = &node; } template Node pop() { T value = static_cast*>(end)->value; if(static_cast*>(end)->prev == nullptr) { start = nullptr; end = nullptr; return value; } end = static_cast*>(end)->prev; static_cast*>(end)->next = nullptr; return value; } template friend std::ostream &operator <<(std::ostream &os, Chain &c) { os << "( "; void* currentNode = c.start; while (static_cast*>(currentNode)->next!=nullptr) { os << *(static_cast*>(currentNode)) << " = "; currentNode = static_cast*>(currentNode)->next; } os << *(static_cast*>(currentNode)) << " )"; return os; } };