常用模板及迭代器的使用方法

vector

定义:

vector< type A> m_vctExpA;

容器迭代器定义:

a 不改变迭代器时:

vector< type A>::const_iterator iter = m_vctExpA.begin();

vector< type A>::const_iterator iterend = m_vctExpA.end();

b 改变迭代器时:

vector< type A>::iterator iter = m_vctExpA.begin();

vector< type A>::iterator iterend = m_vctExpA.end();

迭代器使用:

for( ; iter != iterend; ++iter )    

 {        .........           }

 m_vctExpA.push_back( type A);   //添加元素

void reserve(size_type n);    

size_type capacity() const;    

iterator begin();    

const_iterator begin() const;    

iterator end();    

iterator end() const;    

reverse_iterator rbegin();    

const_reverse_iterator rbegin() const;    

reverse_iterator rend();    

const_reverse_iterator rend() const;    

void resize(size_type n, T x = T());    

size_type size() const;    

size_type max_size() const;    

bool empty() const;    

A get_allocator() const;    

reference at(size_type pos);    

const_reference at(size_type pos) const;    

reference operator[](size_type pos);    

 const_reference operator[](size_type pos);    

reference front();    

const_reference front() const;    

reference back();    

const_reference back() const;    

void push_back(const T& x);    

void pop_back();    

void assign(const_iterator first, const_iterator last);    

void assign(size_type n, const T& x = T());    

iterator insert(iterator it, const T& x = T());    

void insert(iterator it, size_type n, const T& x);    

void insert(iterator it,         const_iterator first, const_iterator last);     iterator erase(iterator it);    

iterator erase(iterator first, iterator last);    

void clear();    

void swap(vector x);

list

定义:

list< type B> m_listA;

容器迭代器定义:

改变迭代器时:

list<  type B>::iterator iter = m_listA.begin();

list<  type B>::iterator iterend = m_listA.end();

for(; iter!=iterend;++iter)

{    }

m_listA.empty();  // 判断是否为空

m_listA.clear();   // 清空

m_listA.push_back( type B);  //添加元素

   void push_front(const T& x);     void pop_front();     void push_back(const T& x);     void pop_back();     void assign(const_iterator first, const_iterator last);     void assign(size_type n, const T& x = T());

iterator insert(iterator it, const T& x = T());     void insert(iterator it, size_type n, const T& x);     void insert(iterator it,         const_iterator first, const_iterator last);     void insert(iterator it,         const T *first, const T *last);     iterator erase(iterator it);     iterator erase(iterator first, iterator last);     void clear();     void swap(list x);     void splice(iterator it, list& x);     void splice(iterator it, list& x, iterator first);     void splice(iterator it, list& x, iterator first, iterator last);     void remove(const T& x);     void remove_if(binder2nd<not_equal_to<T> > pr);     void unique();     void unique(not_equal_to<T> pr);     void merge(list& x);     void merge(list& x, greater<T> pr);     void sort();

set

explicit set(const Pred& comp = Pred(), const A& al = A());     set(const set& x);     set(const value_type *first, const value_type *last,         const Pred& comp = Pred(), const A& al = A());     const_iterator begin() const;     iterator end() const;     const_reverse_iterator rbegin() const;     const_reverse_iterator rend() const;     size_type size() const;     size_type max_size() const;     bool empty() const;     A get_allocator() const;     pair<iterator, bool> insert(const value_type& x);     iterator insert(iterator it, const value_type& x);     void insert(InIt first, InIt last);     iterator erase(iterator it);     iterator erase(iterator first, iterator last);     size_type erase(const Key& key);     void clear();     void swap(set x);     key_compare key_comp() const;     value_compare value_comp() const;     const_iterator find(const Key& key) const;     size_type count(const Key& key) const;     const_iterator lower_bound(const Key& key) const;     const_iterator upper_bound(const Key& key) const;     pair<const_iterator, const_iterator>         equal_range(const Key& key) const;

map

map(const map& x);    

 map(const value_type *first, const value_type *last,      const Pred& comp = Pred(),    const A& al = A());    

iterator begin();    

 const_iterator begin() const;    

iterator end();    

iterator end() const;    

reverse_iterator rbegin();    

const_reverse_iterator rbegin() const;    

reverse_iterator rend();    

 const_reverse_iterator rend() const;  

   size_type size() const;    

size_type max_size() const;   

  bool empty() const;    

 A get_allocator() const;    

A::reference operator[](const Key& key);    

pair<iterator, bool> insert(const value_type& x);    

iterator insert(iterator it, const value_type& x);    

void insert(const value_type *first, const value_type *last);    

iterator erase(iterator it);    

iterator erase(iterator first, iterator last);    

size_type erase(const Key& key);    

void clear();    

void swap(map x);    

key_compare key_comp() const;    

value_compare value_comp() const;    

iterator find(const Key& key);    

const_iterator find(const Key& key) const;    

size_type count(const Key& key) const;    

iterator lower_bound(const Key& key);    

const_iterator lower_bound(const Key& key) const;    

iterator upper_bound(const Key& key);    

const_iterator upper_bound(const Key& key) const;    

pair<iterator, iterator> equal_range(const Key& key);    

pair<const_iterator, const_iterator>   equal_range(const Key& key) const;

 

deque

explicit deque(const A& al = A());    

explicit deque(size_type n, const T& v = T(), const A& al = A());    

deque(const deque& x);    

 deque(const_iterator first, const_iterator last,        

const A& al = A());    

 iterator begin();    

 const_iterator begin() const;    

 iterator end();    

iterator end() const;    

 reverse_iterator rbegin();    

const_reverse_iterator rbegin() const;    

reverse_iterator rend();    

const_reverse_iterator rend() const;    

void resize(size_type n, T x = T());    

size_type size() const;    

 size_type max_size() const;   

  bool empty() const;    

 A get_allocator() const;    

 reference at(size_type pos);    

const_reference at(size_type pos) const;    

 reference operator[](size_type pos);    

const_reference operator[](size_type pos);   

  reference front();     const_reference front() const;    

reference back();     const_reference back() const;   

  void push_front(const T& x);     void pop_front();    

void push_back(const T& x);     void pop_back();   

  void assign(const_iterator first, const_iterator last);    

void assign(size_type n, const T& x = T());    

iterator insert(iterator it, const T& x = T());    

void insert(iterator it, size_type n, const T& x);    

void insert(iterator it,     const_iterator first, const_iterator last);    

iterator erase(iterator it);    

iterator erase(iterator first, iterator last);    

void clear();    

void swap(deque x);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值