Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to push an element onto the stack.
DSA Rust
stack.[1](5);
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'pop' which removes an element instead of adding.
Using 'peek' which only looks at the top element.
✗ Incorrect
The push method adds an element to the top of the stack.
2fill in blank
mediumComplete the code to remove the top element from the stack.
DSA Rust
let top = stack.[1]();Attempts:
3 left
💡 Hint
Common Mistakes
Using 'push' which adds instead of removing.
Using 'peek' which only looks without removing.
✗ Incorrect
The pop method removes and returns the top element from the stack.
3fill in blank
hardFix the error in the code to check the top element without removing it.
DSA Rust
let top = stack.[1]().unwrap();Attempts:
3 left
💡 Hint
Common Mistakes
Using 'pop' which removes the element.
Using 'push' which adds an element.
✗ Incorrect
The last method returns a reference to the top element without removing it.
4fill in blank
hardFill both blanks to create a stack and push an element.
DSA Rust
let mut stack = Vec::[1](); stack.[2](10);
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'pop' to create the stack.
Using 'with_capacity' without adding elements.
✗ Incorrect
Vec::new() creates an empty stack. push adds an element on top.
5fill in blank
hardFill all three blanks to push, peek, and pop elements from the stack.
DSA Rust
stack.[1](20); let top = stack.[2]().unwrap(); let removed = stack.[3]();
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up 'pop' and 'last' methods.
Using 'insert' which is not typical for stack operations.
✗ Incorrect
Use push to add, last to look, and pop to remove the top element.
