A container is a collection of objects that hold a particular type. C + + containers can be divided into two categories: sequential containers and associative containers. The order container's element arrangement is independent of the element value size, but is determined by the order in which the elements are added to the container. The standard library defines
Last in, first out
Queue
Advanced First Out
Priority_queue
The highest priority element is always the first out-of-order
Sequential containers (sequential containers)Define and Initialize:In order to define an object of a container type, you must include the associated header file:#include #include #include Since all containers are class templates, when we want to define a
Introduction to sequential containers :
Sequential Container type
Description
Vector
Variable-size arrays that support fast access and may be slow to insert or delete outside the trailer
Deque
Double-ended queues. Fast access is supported, and insertion and deletion in the kinsoku will be quick.
List
Two-way list. Only bidirectional sequential access is supported.
What is a containerFirst, we have to understand what a container is, in C + +, where a container is defined as having an object type on the Datastore, which can hold other objects or pointers to other pairs of objects, which are called containers. Very simply, a container is an object that holds other objects, which, o
Transferred from: http://blog.csdn.net/wangxiaolong_china/article/details/8362540What is a containerFirst, we have to understand what a container is, in C + +, where a container is defined as having an object type on the Datastore, which can hold other objects or pointers to other pairs of objects, which are called containers. Very simply, a
Tips for C ++ Primer Chapter 9 ordered container, primerchapterChapter 2 Overview of ordered containers
Variable-size vector Array
Deque dual-end queue
List two-way linked list
Forward_list unidirectional linked list (C ++ 11)
Array fixed size array (C ++ 11)
A string is similar to a vector
into a vector
9.2 Container Library Overview
1. Container operation
Type Alias
Iterator type of iterator for this container type
Const_iterator can read elements, but cannot modify the iterator type of elements
Size_type unsigned integer type, sufficient to hold the maximum possible container size for this type of
arithmetic operations (addition or subtraction), nor does it support relational operations (
Iterator scope:
C + + uses a pair of iterators to tag the iterator scope, usually named the primary and last or beg and end. The elements within the range include the elements that the iterator first points to, and all elements from the beginning until the position that the iterator last points to, which is called the left closed interval [first,last).
Ope
Containers in C + + can be roughly divided into two broad categories: sequential containers and associated containers. The sequential container contains a sequential container adapter.Sequential containers : Aggregates elements of a single type into containers and then stores and accesses them based on location. The main vector, list, deque (two-terminal queue).
paragraph 1 Chapter Container
paragraph 1 Caution: Select the container type carefully.
Standard STL sequence Containers: Vector, String, deque, and list.
Standard STL Associative containers: Set, Multiset, map, and Multimap.
Non-standard sequence containers slist and rope. Slist is a one-way list, rope is essentially a "heavy" string.
Non-standard associative containers hash_set, Hase_multiset, Hash_map
The container classes in C + + include "Sequential storage Structure" and "associative storage Structure", which includes vector,list,deque and so on, while the latter includes Set,map,multiset,multimap and so on. If you need to store the number of elements between the compiler can be determined, you can use the array to store, otherwise, you need to use the container
front end of the container (public member function)CendReturns a read-only iterator that points to the end of the container (public member function)CrbeginReturns a read-only reverse iterator that points to the end of the container (public member function)CrendReturns a read-only reverse iterator pointing to the front of the
problem-solving ideas: such as solution, Time complexity O (n) Java source code (spents 373ms):public class Solution {public int maxarea (int[] height) { int max=-1,l=0,r=height.length-1; while (lC Language Source code (spents 12ms):int Maxarea (int* height, int heightsize) { int max=-1,area,l=0,r=heightsize-1,k; while (lC + + source code (spents 30ms):Class Solution {public: int Maxarea (vectorPython source code (spents 152ms):Class solution: # @param {integer[]} h
Container
1th: Carefully select the type of container.
Standard STL sequence containers: Vector, String, deque, and list.
Standard STL Associative containers: Set, Multiset, map, and Multimap.
non-standard sequence containers slist and rope. Slist is a one-way list, rope is essentially a "heavy" string.
non-standard associative containers hash_set, Hase_multiset, Hash_map and Hash_multimap.
vector
vect
With a basic understanding of the data structure, it is easy to understand the concept of containers proposed by advanced languages. Next, let's take a look at C ++Standard Template Library (STL)Provided 10Generic container.
What is container
First, we must understand what a container is.Container is defined as: in dat
C ++ STL vector container learning, stlvector
STL (Standard Template Library) is the most important component of C ++. It provides a set of templates that represent containers, iterators, function objects, and algorithms. The container is the structure of data with the same storage type (such as vector, list, deque, se
The C + + built-in array supports the container's mechanism, but it does not support the semantics of container abstraction. To solve this problem we implement such a class ourselves. in standard C + +, it is implemented with container vectors (vector). A container vector is
Back to General book1. Std::array (c++11 support)Template Array classAn array container is a fixed-length sequence container that stores a certain number of elements in a strictly linear order.The inside of an array container does not maintain any data other than the element itself (even without saving its own size, wh
containers
Some basic operations, such as begin and end members, insert operations, resize operations, erase operations, assign operations, relational operators, and so on.
Self-growth of vector containers
The vector class provides two member functions: Capacity and reserve, which gets the total number of elements that can be stored before the container needs to allocate more storage space, which tells the
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.