diff options
author | Mustafa Quraish <mustafaq9@gmail.com> | 2021-09-16 00:54:50 -0400 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-09-17 16:56:59 +0000 |
commit | 27f28998b10eba3c17cbc3a0bb1ae6fc638a42b3 (patch) | |
tree | 1f9ed46749c69a9f4fbdd80b10f3972d0139c1cd | |
parent | a339b73fc22e97b33e13b426d57a6156513dc07e (diff) | |
download | serenity-27f28998b10eba3c17cbc3a0bb1ae6fc638a42b3.zip |
AK/Vector: Add `Vector::reverse()` method
This reverses the contents of the vector in-place.
-rw-r--r-- | AK/Vector.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/AK/Vector.h b/AK/Vector.h index f13fb1198a..743d7b6a88 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() { |