提交 352dfc5b 编写于 作者: 邹晓航

完成List的头插和尾插

上级 85fdeab5
......@@ -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<class T>
void List<T>::push_front(const value_type& val){
auto node = newNode(val);
node->next = head.p;
head.p = node;
}
template<class T>
void List<T>::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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册