bvectr1.cpp
Upload User: dq031136
Upload Date: 2022-08-08
Package Size: 802k
Code Size: 1k
Development Platform:

C++ Builder

  1. #ifdef __BCPLUSPLUS__
  2. #include <iostream.h>
  3. #include <bvector.h>
  4. #else
  5. #include <iostream>
  6. #include <bvector>
  7. #endif
  8. using namespace std;
  9. const ARRAY_SIZE = 4;
  10. void main(void)
  11. {
  12.    // Dynamically allocated vector begins with 0 elements.
  13.    bit_vector theVector(ARRAY_SIZE);
  14.    // Intialize the array to contain the members [100, 200, 300, 400]
  15.    for (int cEachItem = 0; cEachItem < ARRAY_SIZE; cEachItem++)
  16.       if(cEachItem>1)
  17.       theVector.push_back(cEachItem - 2);
  18.       else
  19.          theVector.push_back(cEachItem);
  20.    cout << "First element: " << theVector.front() << endl;
  21.    cout << "Last element: " << theVector.back() << endl;
  22.    cout << "Elements in vector: " << theVector.size() << endl;
  23.    // Delete the last element of the vector. Remember that the vector
  24.    // is 0-based, so theVector.end() actually points 1 element beyond
  25.    // the end.
  26.    cout << "Deleting last element." << endl;
  27.    theVector.erase(theVector.end() - 1);
  28.    cout << "New last element is: " << theVector.back() << endl;
  29.    // Delete the first element of the vector.
  30.    cout << "Deleting first element." << endl;
  31.    theVector.erase(theVector.begin());
  32.    cout << "New first element is: " << theVector.front() << endl;
  33.    cout << "Elements in vector: " << theVector.size() << endl;
  34.  }