Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to push an operator onto the stack.
DSA Rust
stack.[1](ch);Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() instead of push() removes elements.
Using peek() only looks at the top without adding.
✗ Incorrect
We use push() to add an element to the top of the stack.
2fill in blank
mediumComplete the code to check if the stack is empty.
DSA Rust
if stack.[1]() {
Attempts:
3 left
💡 Hint
Common Mistakes
Using len() without comparing to zero.
Using is_full() which checks if stack is full.
✗ Incorrect
is_empty() returns true if the stack has no elements.
3fill in blank
hardFix the error in the code to pop the top element from the stack.
DSA Rust
let top = stack.[1]().unwrap();Attempts:
3 left
💡 Hint
Common Mistakes
Using peek() which does not remove the element.
Using push() which adds elements instead.
✗ Incorrect
pop() removes and returns the top element; unwrap() gets the value.
4fill in blank
hardFill both blanks to compare operator precedence correctly.
DSA Rust
while !stack.[1]() && precedence(stack.[2]().unwrap()) >= precedence(ch) {
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() inside while condition removes elements prematurely.
Using push() instead of peek() to check top element.
✗ Incorrect
Check stack is not empty with is_empty(), then peek top element for precedence.
5fill in blank
hardFill all three blanks to build the postfix string correctly.
DSA Rust
postfix.push(stack.[1]().unwrap()); stack.[2](ch); while !stack.[3]() {
Attempts:
3 left
💡 Hint
Common Mistakes
Using peek() instead of pop() when adding to postfix.
Checking is_empty() before pushing new operator.
✗ Incorrect
pop() removes top to add to postfix, push() adds current operator, is_empty() checks stack status.
