vector | Array |
list | Doubly-linked list |
slist | Singly-linked list |
queue | FIFO (first-in, first-out) structure |
deque | Array-like structure, with efficient insertion and removal at both ends |
set | Set of unique elements |
stack | LIFO (last in, first out) structure |
The definition of these containers and their iterators are provided in the std namespace, and require to #include the appropriate file, which is always the same name of the container. The examples below show how to use specific containers:
#include <vector>
std::vector<double> values;
#include <queue>
using namespace std;
queue<Order> back_orders;
#include <stack>
using namespace std;
stack<Application_descriptor> undo_list;
std::vector<double> values;
#include <queue>
using namespace std;
queue<Order> back_orders;
#include <stack>
using namespace std;
stack<Application_descriptor> undo_list;
The following member-functions are provided for most containers:
push_front | Inserts element before the first (not available for vector) |
pop_front | Removes the first element (not available for vector) |
push_back | Inserts element after the last |
pop_back | Removes the last element |
Also, most containers provide the following member-functions:
empty | Boolean indicating if the container is empty |
size | Returns the number of elements |
insert | Inserts an element at a particular position |
erase | Removes an element at a particular position |
clear | Removes all the elements |
resize | Resizes the container |
front | Returns a reference to the first element |
back | Returns a reference to the last element |
The vector and deque containers provide subscripting access to elements, and subscripting access with bounds-checking:
[] | Subscripting access without bounds checking |
at | Subscripting access with bounds checking |
No comments:
Post a Comment