#ifndef LINKEDQUEUE_H #define LINKEDQUEUE_H #include "Exception.h" #include "LinkedList.h" #include "Queue.h" #include "utility" #include namespace Kylin { template class LinkedQueue : public Queue { public: LinkedQueue() = default; LinkedQueue(std::initializer_list init) { for (auto &value : init) enqueue(value); } LinkedQueue(LinkedQueue &&other) : m_list(std::move(other.m_list)) {} void swap(LinkedQueue &other) { m_list.swap(other.m_list); } void enqueue(const T &value) final { m_list.append(value); } T dequeue() final { auto value = m_list.at(0); m_list.removeAt(0); return value; } T &head() final { return m_list[0]; } void clear() final { m_list.clear(); } size_t size() const noexcept override { return m_list.size(); } LinkedQueue &operator=(LinkedQueue &&other) { if (&other != this) { swap(other); } return *this; } private: LinkedList m_list; }; } // namespace Kylin #endif // LINKEDQUEUE_H