Преглед изворни кода

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

This reverses the contents of the vector in-place.
Mustafa Quraish пре 3 година
родитељ
комит
27f28998b1
1 измењених фајлова са 6 додато и 0 уклоњено
  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()
     {