Jelajahi Sumber

AK/Vector: Add `Vector::reverse()` method

This reverses the contents of the vector in-place.
Mustafa Quraish 3 tahun lalu
induk
melakukan
27f28998b1
1 mengubah file dengan 6 tambahan dan 0 penghapusan
  1. 6 0
      AK/Vector.h

+ 6 - 0
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()
     {