Complete the code to push an element onto the array-based stack.
void push(int value) {
if (top < capacity - 1) {
stackArray[++[1]] = value;
}
}We increment the 'top' index before assigning the new value to the array position.
Complete the code to pop an element from the linked list stack.
int pop() {
if (head == nullptr) return -1; // stack empty
Node* temp = head;
int poppedValue = head->data;
head = head->[1];
delete temp;
return poppedValue;
}To pop, we move the head pointer to the next node in the linked list.
Fix the error in the array stack's isFull() method.
bool isFull() {
return top [1] capacity - 1;
}The stack is full when 'top' equals 'capacity - 1'.
Fill the blank to correctly check if the linked list stack is empty.
bool isEmpty() {
return head [1] nullptr;
}The stack is empty if head == nullptr.
Fill all three blanks to correctly populate a map with array stack elements greater than 10, using index as key.
auto filtered = std::map<int, int>{};
for (int i = 0; i < size; ++i) {
if (stackArray[i] [3] 10) {
filtered[[1]] = [2];
}
}The code maps index 'i' to stackArray[i] only if stackArray[i] is greater than 10.
