c++ stl vector(针对扩充空间策略)

1.vector

  vector的数据安排以及操作方式,与array非常相似,两者的唯一差别在于空间的运用的灵活性。vector是动态空间,随着元素的加入,它的内部机制会自行扩充空间以容纳新元素。因此,vector的运用对内存的合理利用与运用的灵活性有很大的帮助。vector的实现技术,关键在于对其大小的控制以及重新配置时的数据移动效率。

2.函数成员

2.1构造函数:

/// Creates an empty vector.
vector();
/// Creates a vector with n elements.
vector(size_type n);
/// Creates a vector with n copies of t.
vector(size_type n, const T& t);
/// The copy constructor.
vector(const vector&);
/// Creates a vector with a copy of a range.
template <class InputIterator> vector(InputIterator, InputIterator);

2.2析构函数:

/// The destructor.
~vector();

2.3插入元素:

/// Inserts a new element at the end.
void push_back(const T&);
/// Inserts x before pos.
iterator insert(iterator pos, const T& x);
/// Inserts the range [first, last) before pos.
template <class InputIterator> void insert(iterator pos, InputIterator f, InputIterator l);
/// Inserts n copies of x before pos.
void insert(iterator pos, size_type n, const T& x);

2.4删除元素:

/// Removes the last element.
void pop_back();
/// Erases the element at position pos.
iterator erase(iterator pos);
/// Erases the range [first, last).
iterator erase(iterator first, iterator last);
/// Erases all of the elements.
void clear();
/// Inserts or erases elements at the end such that the size becomes n.
void resize(n, t = T());

2.5返回元素指针或元素:

/// Returns an iterator pointing to the beginning of the vector.
iterator begin();
/// Returns an iterator pointing to the end of the vector.
iterator end();
///
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值