Vector
Last updated
Was this helpful?
Last updated
Was this helpful?
Vector จะเหมือนกับ Dynamic Arrays ที่มีความสามารถในการปรับขนาดตัวเองโดยอัตโนมัติเมื่อมีการแทรกหรือลบองค์ประกอบ โดยคอนเทนเนอร์จะจัดการพื้นที่เก็บข้อมูลโดยอัตโนมัติ
การประกาศ Vector นั้นสามารถทำได้โดยการใช้คำสั่งดังนี้
push_back(): appends an element to the end
pop_back() Erases the last element
size() provides the number of elements
begin() provides reference to last element
end() provides reference to end of Vector.
Iterators (ตัววนซ้ำ)
Output
2. Capacity (ความจุ)
Output
Reference
– Returns an iterator pointing to the first element in the vector
– Returns an iterator pointing to the theoretical element that follows the last element in the vector
– Returns a reverse iterator pointing to the last element in the vector (reverse beginning). It moves from last to first element
– Returns a reverse iterator pointing to the theoretical element preceding the first element in the vector (considered as reverse end)
– Returns a constant iterator pointing to the first element in the vector.
– Returns a constant iterator pointing to the theoretical element that follows the last element in the vector.
– Returns a constant reverse iterator pointing to the last element in the vector (reverse beginning). It moves from last to first element
– Returns a constant reverse iterator pointing to the theoretical element preceding the first element in the vector (considered as reverse end)
– Returns the number of elements in the vector.
– Returns the maximum number of elements that the vector can hold.
– Returns the size of the storage space currently allocated to the vector expressed as number of elements.
– Resizes the container so that it contains ‘n’ elements.
– Returns whether the container is empty.
– Reduces the capacity of the container to fit its size and destroys all elements beyond the capacity.
– Requests that the vector capacity be at least enough to contain n elements.