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();
///