Welcome~~~


Another blog:
http://fun-st.blogspot.com/

It is easier to write an incorrect program than understand a correct one.

Friday, March 4, 2011

C++ Notes Container

vectorArray
listDoubly-linked list
slistSingly-linked list
queueFIFO (first-in, first-out) structure
dequeArray-like structure, with efficient insertion and removal at both ends
setSet of unique elements
stackLIFO (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;


The following member-functions are provided for most containers:
push_frontInserts element before the first    (not available for vector)
pop_frontRemoves the first element    (not available for vector)
push_backInserts element after the last
pop_backRemoves the last element


Also, most containers provide the following member-functions:
emptyBoolean indicating if the container is empty
sizeReturns the number of elements
insertInserts an element at a particular position
eraseRemoves an element at a particular position
clearRemoves all the elements
resizeResizes the container
frontReturns a reference to the first element
backReturns 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
atSubscripting access with bounds checking

No comments:

Post a Comment