Design a Stack With Increment Operation LeetCode solution in C++
1class CustomStack {2int *data;3int nextIndex;4int capacity;56public:7CustomStack(int maxSize) {8data = new int[maxSize];9nextIndex = 0;10capacity = maxSize;11}1213void push(int x) {14if (nextIndex == capacity) {15return;16}17data[nextIndex] = x;18nextIndex++;19}2021int pop() {22if (nextIndex == 0) {23return -1;24}25int temp = data[nextIndex - 1];26nextIndex--;27return temp;28}2930void increment(int k, int val) {31// loop will run upto nextIndex if k >= nextIndex else runt upto k only32int n = (k >= nextIndex) ? nextIndex : k;33for (int i = 0; i < n; i++) {34data[i] = data[i] + val;35}36}37};