The task is to implement a custom vector class similar to the STL vector with following functions:
- int push_back(data): adds an element(of any data_type) to the end of array and also returns the number of elements in that vector
- data_type pop_back(): removes an element from the end of array, also returns the popped element
- int size() const: returns the current size of vector
Below program implements a custom vector class in C++ with above mentioned functionalities:
For Integer data_type Element in vector v : 5 6 7 8 9 10 11 12 size: 8 v: 7 Popped Element: 12 5 6 7 8 9 10 11 For Char data_type Element in vector c : a b c d e f g h size: 8 c: c pop: h Element in vector c : a b c d e f g
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- How to create a custom String class in C++ with basic functionalities
- vector::front() and vector::back() in C++ STL
- vector::push_back() and vector::pop_back() in C++ STL
- vector::operator= and vector::operator[ ] in C++ STL
- vector::at() and vector::swap() in C++ STL
- vector::crend() & vector::crbegin() with example
- vector :: cbegin() and vector :: cend() in C++ STL
- How to flatten a Vector of Vectors or 2D Vector in C++
- vector::empty() and vector::size() in C++ STL
- vector::begin() and vector::end() in C++ STL
- User-defined Custom Exception with class in C++
- Using class to implement Vector Quantities in C++
- How to implement our own Vector Class in C++?
- Program to find frequency of each element in a vector using map in C++
- Custom Jumble Word Game
- How to create a dynamic 2D array inside a class in C++ ?
- How to create an unordered_map of user defined class in C++?
- How to create an unordered_set of user defined class or struct in C++?
- How to convert a class to another class type in C++?
- Difference between Base class and Derived class in C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.