define vector code example

Example 1: c++ vector

#include <vector>

int main() {
  std::vector<int> v;
  v.push_back(10); // v = [10];
  v.push_back(20); // v = [10, 20];
  
  v.pop_back(); // v = [10];
  v.push_back(30); // v = [10, 30];
  
  auto it = v.begin();
  int x = *it; // x = 10;
  ++it;
  int y = *it; // y = 30
  ++it;
  bool is_end = it == v.end(); // is_end = true
  
  return 0;
}

Example 2: vector

In mathematics, physics and engineering, a Euclidean vector
is a geometric object that has magnitude and direction. 
Vectors can be added to other vectors according to vector algebra

Examples include:

1.)displacement
2.)velocity
3.)position
4.)force
5.)torque

Example 3: what is vector

Array based data structure
-It is synchronized - thread safe.
-It is mostly used in multi-threaded environment.
-It is much slower than ArrayList because it is
thread-safe

Tags:

Cpp Example