From c49b2f955931ec3bfa5fa9e717df4ffed16fbe66 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, 29 Nov 2014 16:50:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=3D=3D=E5=92=8C=EF=BC=81=3D?= =?UTF-8?q?=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/List.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/TinySTL/List.h b/TinySTL/List.h index caac360..a11f8d6 100644 --- a/TinySTL/List.h +++ b/TinySTL/List.h @@ -30,7 +30,7 @@ namespace TinySTL{ struct listIterator :public bidirectional_iterator{ template friend class list; - private: + public: typedef node* nodePtr; nodePtr p; public: @@ -209,6 +209,10 @@ namespace TinySTL{ public: template friend void swap(list& x, list& y); + template + friend bool operator== (const list& lhs, const list& rhs); + template + friend bool operator!= (const list& lhs, const list& rhs); }; template void list::push_front(const value_type& val){ @@ -432,6 +436,21 @@ namespace TinySTL{ this->splice(it1, x, it2, x.end()); } } + template + bool operator== (const list& lhs, const list& rhs){ + auto node1 = lhs.head.p, node2 = rhs.head.p; + for (; node1 != lhs.tail.p && node2 != rhs.tail.p; node1 = node1->next, node2 = node2->next){ + if (node1->data != node2->data) + break; + } + if (node1 == lhs.tail.p && node2 == rhs.tail.p) + return true; + return false; + } + template + bool operator!= (const list& lhs, const list& rhs){ + return !(lhs == rhs); + } } #endif \ No newline at end of file