Bird
0
0
DSA Cprogramming~10 mins

Stack Concept and LIFO Principle 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 a stack array of size 5.

DSA C
int stack[[1]];
Drag options to blanks, or click blank then click option'
A5
B7
C3
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using a size other than 5.
Forgetting to specify the size.
2fill in blank
medium

Complete the code to initialize the top of the stack to -1.

DSA C
int top = [1];
Drag options to blanks, or click blank then click option'
A1
B0
C-1
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Setting top to 0 which means stack has one element.
Using positive numbers initially.
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;
    }
}
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction which moves top backward.
Using multiplication or division which is incorrect here.
4fill in blank
hard

Fill both blanks to correctly pop an element from the stack.

DSA C
int pop(int stack[], int *top) {
    int value = stack[*top];
    *top = *top [1] 1;
    return value;
}
Drag options to blanks, or click blank then click option'
A/
B+
C*
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition which moves top forward incorrectly.
Using multiplication or division which is invalid here.
5fill in blank
hard

Fill all three blanks to check if the stack is empty and print a message.

DSA C
if (top [1] [2]) {
    printf("Stack is [3]\n");
}
Drag options to blanks, or click blank then click option'
A==
B!=
C-1
Dempty
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '=='.
Comparing top with 0 instead of -1.
Printing wrong message.