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