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
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- User-defined Custom Exception with class in C++
- How to implement our own Vector Class in C++?
- Using class to implement Vector Quantities in C++
- How to create an unordered_map of user defined class in C++?
- How to create a dynamic 2D array inside a class in C++ ?
- How to create an unordered_set of user defined class or struct in C++?
- Program to find frequency of each element in a vector using map in C++
- C++ program to create a file
- Create Directory or Folder with C/C++ Program
- How to flatten a Vector of Vectors or 2D Vector in C++
- vector :: cbegin() and vector :: cend() in C++ STL
- vector::crend() & vector::crbegin() with example
- vector::empty() and vector::size() in C++ STL
- vector::push_back() and vector::pop_back() in C++ STL
- vector::front() and vector::back() in C++ STL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.