Basic Sequence Container Properties

◀ Basic Container Properties▶ Vector and List - Part 1
Amazon Out of the eleven C++ container types, vector, stack, queue, deque, list, and priority_queue are also known as sequences. A sequence, as its name suggests, has the property that its elements are arranged in linear order, which means operations such as removing and inserting elements at particular locations become feasible.

In addition to the basic container properties these sequence types have the following additional properties.

In the following table, C represents a container type, including its identifier, such as vector<string> and list<int>; a represents an object of C; n is an integer; c is a value of the identifier; i and j are iterators. Here is something you must note: a is an object of C and c is a value of C’s identifier. For example, in the statement
vector<string> concert;
vector<string> is C, concert is a, “A String” is c (c is any value of type string).
ExpressionExplanation
C a(i, j);creates a sequence initialized to the contents of range [i, j)
C a(n, c);creates a sequence of n copies of c
a.erase(i, j);erases the contents of range [i, j)
a.erase(p);erases the element p points to
a.clear();erases all elements
a.insert(p, c);inserts before p one copy of c
a.insert(p, n, c);inserts before p n copies of c
a.insert(p, i, j);inserts before p elements of range [i, j)
As you can see the operations described in the table above are related to manipulating a sequence regardless of their implementation.
Next we’ll take a look at the vector and list, two of the most common sequence containers worth extra mentioning!
◀ Basic Container Properties▶ Vector and List - Part 1

fShare
Questions? Let me know!