/*
*
**************************************** ****
* Basic descriptions of bit_vector containers:
**************************************** ****
*
* It has the same member functions as a vector container and is often used for hardware port control.
* Different from Vector Bit_vector saves more memory space. One element only occupies one bit.
*
* Note that bit_vector is not a template class.
*
* I personally think this type is mostly used for hardware port control.
*
* 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.
* To use bit_vector, you must use a macro statement # include
*
**************************************** **************************************** ******
*
* Create a vector object:
* 1. bit_vector A; // A is 0 or 1.
* 2. bit_vector A (10); // object a with 10 elements. The default value of each element is 1.
* 3. bit_vector A (size_t N, bool value); // object a of n bit element values, each element value is determined by the value
* 4. bit_vector B (a); // bit_vector C (A. Begin (), A. End () can also pass the bool array address value
*
**************************************** **************************************** ******
*
* Initialization assignment
* Void push_back (bool value );
*
**************************************** **************************************** ******
*
* Traversal
* Iterator begin (); iterator end ();
* Reverse_iterator rbegin (); reverse_iterator rend ();
* Reference operator [] (size_type N); // you can use arrays to access the bit_vector element.
*
**************************************** **************************************** ******
*
* Common functions
*
* Bool empty ();
* Size_type size (); size_type max_size (); size_type capacity ();
* Iterator insert (iterator POs, bool X );
*
* Reference Front (); reference back (); // return the first and last elements respectively.
* Void pop_back (); void push_back ();
*
* Void swap (bit_vector &);
* Void swap (bit_reference X, bit_reference y );
*
* Iterator erase (iterator POS );
* Iterator erase (iterator first, iterator last); // note that the semi-closed interval [first, last)
* Void clear ();
*
*
*
**************************************** ****
* Author: cumirror
* Email: tongjinooo@163.com
**************************************** ****
*
*/
// The usage is similar to that of vector. If you are interested, you can write the code yourself.
# Include
# Include
Int main ()
{
Using namespace STD;
Bit_vector A (10, true );
For (int s = 0; s
Previous Article: C ++ STL study Note 5 slist one-way linked list container
Next article: C ++ STL study Note 3 deque dual-end queue container