Design a Dynamic Array (aka a resizable array) class, such as an ArrayList in Java or a vector in C++.
Your Dynamic Array should support the following operations:
DynamicArray(int capacity)will initialize an empty array with a capacity ofcapacity, wherecapacity > 0.int get(int i)will return the element at indexi. Assume that indexiis valid.void set(int i, int n)will set the element at indexiton. Assume that indexiis valid.void pushback(int n)will push the elementnto the end of the array.int popback()will pop and return the element at the end of the array. Assume that the array is non-empty.void resize()will double the capacity of the array.int getSize()will return the number of elements in the array.int getCapacity()will return the capacity of the array.
If we insert an element when the size of the array is equal to the capacity, the resize() function should be called.
length
0
0
0
1
0
2
capacity=3
Step 1 / 7
Step 1:
Start with capacity=3 and length=0 (no elements are “active” yet).
Pointers: length=0
Focus: default
capacity=3