From 352dfc5b8be9381187f995cc1041215059533c11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Wed, 26 Nov 2014 09:53:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90List=E7=9A=84=E5=A4=B4?= =?UTF-8?q?=E6=8F=92=E5=92=8C=E5=B0=BE=E6=8F=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/List.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/TinySTL/List.h b/TinySTL/List.h index 8cc9ed4..30cd4f6 100644 --- a/TinySTL/List.h +++ b/TinySTL/List.h @@ -70,6 +70,22 @@ namespace TinySTL{ head.p = newNode();//add a dummy node tail.p = head.p; } + /*List(const List& list){ + + }*/ + ~List(){ + for (; head != tail;){ + auto temp = head++; + nodeAllocator::deallocate(temp.p); + } + nodeAllocator::deallocate(tail.p); + } + + void push_front(const value_type& val); + void push_back(const value_type& val); + + iterator begin()const{ return head; } + iterator end()const{ return tail; } private: nodePtr newNode(const T& val = T()){ nodePtr res = nodeAllocator::allocate(); @@ -79,6 +95,19 @@ namespace TinySTL{ return res; } }; + template + void List::push_front(const value_type& val){ + auto node = newNode(val); + node->next = head.p; + head.p = node; + } + template + void List::push_back(const value_type& val){ + auto node = newNode(); + (tail.p)->data = val; + (tail.p)->next = node; + tail.p = node; + } } #endif \ No newline at end of file