Basic Sequence Container Properties
◀ Basic Container Properties▶ Vector and List - Part 1 Amazon
ut of the eleven C++ container types, vector
, 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>
represents an object of C
is an integer; c
is a value of the identifier; i
are iterators. Here is something you must note: a
is an object of C
is a value of C
’s identifier. For example, in the statement
, “A String” is c
is any value of type string
As you can see the operations described in the table above are related to manipulating a sequence regardless of their implementation.
|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)|
Next we’ll take a look at the vector
, two of the most common sequence containers worth extra mentioning!
◀ Basic Container Properties▶ Vector and List - Part 1