From 5740c7239c7ab55fb21f4072c47242035337d240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Sat, 25 Oct 2014 10:54:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90queue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/Queue.h | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/TinySTL/Queue.h b/TinySTL/Queue.h index 52a9b5c..0ea6333 100644 --- a/TinySTL/Queue.h +++ b/TinySTL/Queue.h @@ -7,8 +7,49 @@ namespace TinySTL{ //class of queue - template> - class queue{}; + template> + class queue{ + public: + typedef T value_type; + typedef Container container_type; + typedef typename Container::reference reference; + typedef typename Container::const_reference const_reference; + typedef typename Container::size_type size_type; + private: + Container container_; + public: + queue(){} + explicit queue(const container_type& ctnr) :container_(ctnr){} + + bool empty() const{ return container_.empty(); } + size_type size() const{ return container_.size(); } + reference& front(){ return container_.front(); } + const_reference& front() const{ return container_.front(); } + reference& back(){ return container_.back(); } + const_reference& back() const{ return container_.back(); } + void push(const value_type& val){ container_.push_back(val); } + void pop(){ container_.pop_front(); } + void swap(queue& x){ container_.swap(x.container_); } + public: + template + friend bool operator== (const queue& lhs, const queue& rhs); + template + friend bool operator!= (const queue& lhs, const queue& rhs); + template + friend void swap(queue& x, queue& y); + }; + template + bool operator== (const queue& lhs, const queue& rhs){ + return lhs.container_ == rhs.container_; + } + template + bool operator!= (const queue& lhs, const queue& rhs){ + return lhs.container_ != rhs.container_; + } + template + void swap(queue& x, queue& y){ + TinySTL::swap(x.container_, y.container_); + } //class of priority_queue template , class Compare = TinySTL::less>