SirYakalot SirYakalot - 2 months ago 15
C++ Question

How do I reverse a C++ vector?

Is there a built-in vector function in C++ to reverse a vector in place?

Or do you just have to do it manually?


There's a function std::reverse in the algorithm header for this purpose.

#include <vector>
#include <algorithm>

int main() {
  std::vector<int> a;
  std::reverse(a.begin(), a.end());
  return 0;