/*
*
**************************************** ****
* Basic instructions for vector containers:
**************************************** ****
*
* Random access is allowed, and new elements are inserted at the end of the container.
* Random Access container and back Insertion Sequence
* The time complexity for inserting and deleting elements at the end is O (1), the other positions are O (n), and N is the number of elements.
* The occupied space of inserted elements can be dynamically adjusted.
* The macro statement # include <vector> must be used to use vector.
*
**************************************** **************************************** ******
*
* Create a vector object:
* 1. Vector <int>;
* 2. Vector <int> A (10); // object a with 10 elements. The default value of each element is 0.
* 3. Vector <char> A (5, 'k ');
* 4. Vector <char> B (a); // vector <char> C (A. Begin (), A. End ())
*
**************************************** **************************************** ******
*
* Initialization assignment
* Void push_back (const T & value)
*
**************************************** **************************************** ******
*
* Traversal
* Reference operator [] (size_type N) // you can use arrays to access the vector element.
*
**************************************** **************************************** ******
*
* Common functions
*
* Bool empty ();
* Size_type size (); size_type max_size (); size_type capacity ();
* Reference Front (); reference back ();
* Void pop_back (); void push_back ();
* Void clear ();
*
*
*
**************************************** ****
* Author: cumirror
* Email: tongjinooo@163.com
**************************************** ****
*
*/
# Include <iostream>
# Include <vector>
Int main ()
{
Using namespace STD;
Vector <int> A (10, 5 );
// Array
Cout <"array" <Endl;
A [0] = 100;
For (int s = 0; S <A. Size (); s ++ ){
Cout <A [s] <Endl;
}
// Iterator Method
Cout <"iterator" <Endl;
Vector <int>: iterator I, iend;
I = A. Begin ();
Iend = A. End ();
* I = 101;
For (vector <int>: iterator J = I; J! = Iend; j ++ ){
Cout <* j <Endl;
}
// Insert an element before the iterator
// Note: After element insertion, the original iterator will become invalid.
Cout <"insert" <Endl;
A. insert (A. Begin (), 102 );
// Note when deleting a table. It is a semi-closed interval.
// Deletion of a single element of erase (iterator POS) is also supported.
Cout <"delete" <Endl;
A. Erase (A. Begin () + 4, A. Begin () + 6 );
For (vector <int>: iterator K = A. Begin (); k! = A. End (); k ++ ){
Cout <* k <Endl;
}
// Reverse Traversal
Cout <"reverse access" <Endl;
Vector <int>: reverse_iterator Ri;
For (Ri = A. rbegin (); Ri! = A. rend (); ri ++ ){
Cout <* RI <Endl;
}
Return 0;
}