STL list的insert push_front push_back成员函数实现

 
/*stl_list.h文件中*/
 
 
iterator insert(iterator position, const T& x) {
	link_type tmp = create_node(x);

	tmp->next = position.node;
	tmp->prev = position.node->prev;

	(link_type(position.node->prev))->next = tmp;
	position.node->prev = tmp;

	return tmp;
}
 
 
 
void push_front(const T& x) { insert(begin(), x); }
void push_back(const T& x) { insert(end(), x); }

 
 

posted @ 2013-01-04 15:30  helloweworld  阅读(458)  评论(0编辑  收藏  举报