Open In App

Program to create Custom Vector Class in C++

Last Updated : 01 Jul, 2021
Comments
Improve
Suggest changes
4 Likes
Like
Report

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: 
 


Output: 
For Integer data_type
Element in vector v : 5 6 7 8 9 10 11 12 
size: 8
v[2]: 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[2]: c
pop: h
Element in vector c : a b c d e f g

 

Next Article
Practice Tags :

Similar Reads