C ++ STL learning notes 6 bit_vector bit vector container

Source: Internet
Author: User
/*
*
**************************************** ****
* 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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.