Complete the code to push an element onto the stack.
void push(int stack[], int *top, int value) {
stack[++[1]] = value;
}The top pointer is incremented first, then the value is assigned at that position.
Complete the code to pop an element from the stack.
int pop(int stack[], int *top) {
if (*top == -1) return -1; // stack empty
return stack[[1]--];
}Return the current top element, then decrement the top pointer.
Fix the error in the stack overflow check condition.
int isFull(int top, int maxSize) {
return [1] >= maxSize - 1;
}The top index is compared to maxSize - 1 to check if stack is full.
Fill both blanks to check if the stack is empty and return the top element safely.
int safePop(int stack[], int *top) {
if (*top [1] -1) return -1;
return stack[[2]--];
}Check if top equals -1 to detect empty stack, then return element at *top and decrement.
Fill all three blanks to implement a function that returns the current top element without popping it.
int peek(int stack[], int *top) {
if (*top [1] -1) return -1;
return stack[[2]];
// top remains [3]
}Check if stack is empty by comparing *top to -1, then return element at *top without changing top.
