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
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- How to create a custom String class in C++ with basic functionalities
- 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 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++?
- 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
- vector::empty() and vector::size() in C++ STL
- vector::crend() & vector::crbegin() with example
- vector::front() and vector::back() in C++ STL
- vector::push_back() and vector::pop_back() in C++ STL
- vector :: cbegin() and vector :: cend() in C++ STL
- How to flatten a Vector of Vectors or 2D Vector in C++
- OpenCV C++ Program to create a single colored blank image
- C++ Program to print Fibonacci Series using Class template
- vector::at() and vector::swap() in C++ STL
- vector::begin() and vector::end() 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 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.