C++primer 5th Edition Reading notes (Chapter 9th)

Source: Internet
Author: User

9th Chapter Sequential Container
9.1 Sequential Container Overview

    1. Basic principles for selecting containers:
      • Vectors should be used unless there are good reasons to choose other containers;
      • If the program has many small elements and the extra overhead of space is important, do not use list or forward_list;
      • If the program requires random access to elements, the vector or deque should be used;
      • If the program requires inserting or deleting elements in the middle of the container, use list or forward_list;
      • Use Deque if the program needs to insert or delete elements at the beginning and tail, but not insert or delete in the middle;
      • If the program needs to insert elements in the middle of the container only when the input is read, then random access to the elements is required:
        A) First, determine if you really need to add elements in the middle of the container. When working with input data, it is often easy to append data to the vector and then reorder it by invoking the sort function of the standard library to avoid adding elements in an intermediate position.
        b) If the element must be inserted in an intermediate position, consider using list in the input phase, and once the input is complete, copy the contents of the list into a vector.

9.2 Container Library Overview


9.2.4 Container definition and initialization

9.2.5 Assignment and Swap

    1. Swap does not copy, delete, or insert any elements except array, so it is guaranteed to complete in constant time;

9.3 Sequential Container Operations
9.3.1 adding elements to a sequential container

9.3.2 accessing elements

9.3.3 deleting elements

9.3.4 Special Forward_list operation

9.3.5 Changing the container size


9.5.1 other ways to construct string


9.5.2 other ways to change string


9.5.3 String Search operation


9.5.4 Compare function

9.5.5 Numeric conversions

9.6 Container Adapter

Stack Adapter

Queue Adapter

C++primer 5th Edition Reading notes (Chapter 9th)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.