Bird
0
0
DSA Cprogramming~10 mins

Stack Implementation Using Array in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare the stack array with a maximum size of 5.

DSA C
int stack[[1]];
Drag options to blanks, or click blank then click option'
A10
B1
C0
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or 1 as the size which creates an invalid or too small array.
Using 10 which is larger than the required size.
2fill in blank
medium

Complete the code to initialize the top of the stack to -1, indicating an empty stack.

DSA C
int top = [1];
Drag options to blanks, or click blank then click option'
A-1
B0
C1
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Setting top to 0 which implies the stack has one element.
Using 5 which is out of array bounds.
3fill in blank
hard

Fix the error in the push function to correctly add an element to the stack.

DSA C
void push(int stack[], int *top, int value) {
    if (*top < 4) {
        *top = *top [1] 1;
        stack[*top] = value;
    } else {
        printf("Stack Overflow\n");
    }
}
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' which decreases the top index incorrectly.
Using '*' or '/' which are not suitable for incrementing.
4fill in blank
hard

Fill in the blank to correctly implement the pop function that removes and returns the top element.

DSA C
int pop(int stack[], int *top) {
    if (*top >= 0) {
        int value = stack[*top];
        *top = *top [1] 1;
        return value;
    } else {
        printf("Stack Underflow\n");
        return -1;
    }
}
Drag options to blanks, or click blank then click option'
A*
B-
C/
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' which incorrectly increases the top index.
Using '*' or '/' which are invalid here.
5fill in blank
hard

Fill all three blanks to complete the isEmpty function that checks if the stack is empty.

DSA C
int isEmpty(int [1][], int [2]) {
    if ([3] == -1) {
        return 1;
    } else {
        return 0;
    }
}
Drag options to blanks, or click blank then click option'
Astack
Btop
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable names or missing parameters.
Checking the wrong condition for emptiness.