Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to push an element onto the stack.
DSA C++
stack.push([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() instead of the value to push.
Calling top() which only returns the top element.
Using empty() which checks if the stack is empty.
✗ Incorrect
The push operation adds the given value to the top of the stack.
2fill in blank
mediumComplete the code to declare a stack of integers.
DSA C++
std::stack<[1]> stack;Attempts:
3 left
💡 Hint
Common Mistakes
Using float or string instead of int.
Confusing bool with int.
✗ Incorrect
The stack is declared to hold integers using std::stack.
3fill in blank
hardFix the error in the push operation code.
DSA C++
stack.[1](10);
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() which removes elements.
Using top() which only accesses the top element.
Using empty() which checks if stack is empty.
✗ Incorrect
The correct method to add an element is push, not pop or top.
4fill in blank
hardFill both blanks to create a stack and push a value 5.
DSA C++
std::stack<[1]> stack; stack.[2](5);
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop instead of push.
Using float instead of int.
✗ Incorrect
Declare stack of int and use push to add 5.
5fill in blank
hardFill all three blanks to push the top element's value plus 1 onto the stack.
DSA C++
int topValue = stack.[1](); stack.[2](topValue [3] 1);
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() instead of top().
Using - instead of +.
Using pop() instead of push() to add.
✗ Incorrect
Use top() to get the top element, push() to add, and + to add 1.
