C++语言程序设计 清华大学郑莉 顺序容器 ·顺序容器的接口 赋值 顺 ●assign 序 一插入函数 ·insert,push_front(只对list和deque),push_back 容 删除函数 器 ●erase,clear,pop_front(只对list和deque), pop back 一其他顺序容器访问函数 ●front,back 改变大小 ●resize
C++语言程序设计 清华大学 郑莉 16 顺序容器 ⚫ 顺序容器的接口 – 赋值 ⚫ assign – 插入函数 ⚫ insert, push_front(只对list和deque), push_back – 删除函数 ⚫ erase,clear,pop_front(只对list和deque) , pop_back – 其他顺序容器访问函数 ⚫ front,back – 改变大小 ⚫ resize 顺 序 容 器
C++语言程序设计 清华大学郑莉 例10-4 /包含的头文件略去… template〈class T> void printContainer(const char*msg,const T&s){ 序 cout <msg <"" copy(s.begin(),s.end(,ostream_iterator<int>(cout,"")) 容 cout <endl; 器 int main(){ deque<int>s; for (int i=0;i<10;i++){ int x; cin >x; s.push_front(x); 17
C++语言程序设计 清华大学 郑莉 例10-4 17 顺 序 容 器 //包含的头文件略去…… template <class T> void printContainer(const char* msg, const T& s) { cout << msg << ": "; copy(s.begin(), s.end(), ostream_iterator<int>(cout, " ")); cout << endl; } int main() { deque<int> s; for (int i = 0; i < 10; i++) { int x; cin >> x; s.push_front(x); }