Ch03List,Stacks,andQueues课件.ppt

  1. 1、本文档共46页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Ch03List,Stacks,andQueues课件

Vector and list in the STL STL:Standard Template Library Collection or container Two popular implementations of the List ADT: Vector : provides a growable array implementation list : provides a doubly linked list implementation 3 methods available for all the STL containers: Int size() Void clear() Bool empty() methods available for vector and list: Void push_back(const Object x) Void pop_back() Const Object back() const Const Object front() const methods available for list only: Void push_front(const Object x) Void pop_front() methods available for vector only: Object operator[](int idx) Object at(int idx) Int capacity() const Void reserve(int new capacity) Iterator Liststring::iterator Vectorint::iterator Getting the iterator Iterator begin(): Iterator end() Iterator methods Itr++,++itr *itr Itr1==itr2 Itr1! Container operations that require iterators Iterator insert(iterator pos,const object x) Iterator erase(iterator pos) Iterator erase(iterator start,iterator end) Example:using erase on a list Const-iterators Implementation of vector Some important features of C++ primitive arrays: The array is simply a pointer variable to a block of memory; the actual array size must be maintained separately by the programmer. The block of memory can be allocated via new[],but then must be freed via delete[]. The block of memory cannot be resized(but a new presumably larger block can be obtained and initialized with the old block, and then the old block can ben freed). The main details of Vector The Vector will maintain the primitive array, the array capacity, and the current number of items stored in the Vector. Will implement the Big-Three to provide deep-copy semantics for the copy constructor and operator=,and will provide a destructor to reclaim the primitive array. Will provide a resize routine that will change the size of the Vector and a reserve routine that will change the capacity of the Vector. Will provide an implementation of operator[] Will provide

文档评论(0)

haihang2017 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档