Programming with Sikander https://youtu.be/fx5rq7A9zSE?si=t4b5aXt87ICQ_Wla https://youtu.be/Apf0rYhEIz0?si=8Q9nFgGVsioEZ6vT https://youtu.be/wWiFujF5AiE?si=4_NOVAGnmIED-tsE https://youtu.be/gIGEMi4S5iw?si=cc4rp2w5EzrOH1zw
Programming with Sikander : STL Containers : vector  vector is a sequence container that encapsulates dynamic size arrays.  The storage of the vector is handled automatically, being expanded and contracted as needed.  The elements are stored contiguously.  Random Access is supported
Programming with Sikander : STL Containers : vector
Programming with Sikander : STL Containers : vector
Programming with Sikander : STL Containers : vector
Programming with Sikander : STL Containers : vector
Programming with Sikander : STL Containers : vector  push_back : Add element at the end  void push_back (const value_type& val);
Programming with Sikander : STL Containers : vector
Programming with Sikander : STL Containers : vector
Programming with Sikander : STL Containers : vector
Programming with Sikander : STL Containers : vector
Programming with Sikander : STL Containers : vector  pop_back : Delete last element  void pop_back();
Programming with Sikander : STL Containers : vector
Programming with Sikander : STL Containers : vector  Clear : Removes all elements from the vector (which are destroyed), leaving the container with a size of 0.  void clear();
Programming with Sikander : STL Containers : vector
Programming with Sikander : STL Containers : vector  Front : Access first element  reference front();  Back : Access last element  reference back();  emptyTest whether vector is empty  bool empty() const;
Programming with Sikander : STL Containers : vector  https://www.youtube.com/watch?v=wWiFujF5AiE
Programming with Sikander : STL Containers : vector  reserve : Increase the capacity of the vector  void reserve(size_type new_cap);  The reserve method increases the capacity of a vector to a specified size.  It does this without changing the current size of the vector.  Useful for optimizing performance by reducing reallocations.
Programming with Sikander : STL Containers : vector
Programming with Sikander : STL Containers : vector
Programming with Sikander : STL Containers : vector  Iterator is pointer like object.  vector<int>::iterator it;  To get the address of first element of vector  v.begin( );  To get the end address of vector  v.end( );
Programming with Sikander : STL Containers : vector  Arithmetic Operators :  Iterator + int,  Iterator – int  Iterator – iterator  ++,  --  Relational Operators : >, >=, <, <=, != , ==
Programming with Sikander : STL Containers : vector
Programming with Sikander : STL Containers : vector
Programming with Sikander : STL Containers : vector
Programming with Sikander : STL Containers : vector  Reverse Iterators: They work similar to normal iterators but move in the opposite direction.  rbegin: Returns a reverse iterator pointing to the last element in the container (i.e., the reverse beginning).  rend : Returns a reverse iterator pointing to the theoretical element preceding the first element in the container (i.e., the reverse end).
Programming with Sikander : STL Containers : vector
Programming with Sikander : STL Containers : vector  Insert  The vector is extended by inserting new elements before the element at the specified position, effectively increasing the container size by the number of elements inserted.  iterator insert (iterator position, const value_type& val);
Programming with Sikander : STL Containers : vector
Programming with Sikander : STL Containers : vector
Programming with Sikander : STL Containers : vector  Erase  Removes from the vector either a single element (position) or a range of elements ([first,last)).  This effectively reduces the container size by the number of elements removed, which are destroyed.  iterator erase (iterator position);  iterator erase (iterator first, iterator last);
Programming with Sikander : STL Containers : vector Delete a element at a given position cout << “Enter the position “ ; cin >> pos; v.erase( v.begin() + pos); Delete a key element cout << “Enter the element “ ; cin >> ele; Vector<int> iterator it; it = find(v.begin() , v.end() , ele); if(it != v.end()) v.erase( it);
Programming with Sikander : STL Containers : vector
Programming with Sikander : STL Containers : vector
Programming with Sikander : STL Containers : vector

STL Containers in C++ : Sequence Container : Vector