From 27f28998b10eba3c17cbc3a0bb1ae6fc638a42b3 Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Thu, 16 Sep 2021 00:54:50 -0400 Subject: [PATCH] AK/Vector: Add `Vector::reverse()` method This reverses the contents of the vector in-place. --- AK/Vector.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/AK/Vector.h b/AK/Vector.h index f13fb1198ab..743d7b6a888 100644 --- a/AK/Vector.h +++ b/AK/Vector.h @@ -746,6 +746,12 @@ public: return {}; } + void reverse() + { + for (size_t i = 0; i < size() / 2; ++i) + AK::swap(at(i), at(size() - i - 1)); + } + private: void reset_capacity() {