Browse Source

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

This reverses the contents of the vector in-place.
Mustafa Quraish 3 năm trước cách đây
mục cha
commit
27f28998b1
1 tập tin đã thay đổi với 6 bổ sung0 xóa
  1. 6 0
      AK/Vector.h

+ 6 - 0
AK/Vector.h

@@ -746,6 +746,12 @@ public:
         return {};
         return {};
     }
     }
 
 
+    void reverse()
+    {
+        for (size_t i = 0; i < size() / 2; ++i)
+            AK::swap(at(i), at(size() - i - 1));
+    }
+
 private:
 private:
     void reset_capacity()
     void reset_capacity()
     {
     {