Complete the code to check if the stack is empty.
fn is_empty(stack: &Vec<i32>) -> bool {
stack.[1]()
}The is_empty() method returns true if the stack has no elements.
Complete the code to check if the stack is full given its capacity.
fn is_full(stack: &Vec<i32>, capacity: usize) -> bool {
stack.len() == [1]
}The stack is full when its current length equals its capacity.
Fix the error in the function that checks if the stack is empty.
fn check_empty(stack: &Vec<i32>) -> bool {
if stack.[1]() {
true
} else {
false
}
}The is_empty() method returns a boolean directly, so the if-else can use it correctly.
Fill both blanks to create a function that returns true if the stack is full.
fn check_full(stack: &Vec<i32>, max_size: usize) -> bool {
stack.[1]() == [2]
}The function compares the current length of the stack with the maximum allowed size.
Fill all three blanks to create a function that returns a message about stack status.
fn stack_status(stack: &Vec<i32>, capacity: usize) -> String {
if stack.[1]() {
String::from("Stack is empty")
} else if stack.[3]() == [2] {
String::from("Stack is full")
} else {
String::from("Stack has space")
}
}The function checks if the stack is empty using is_empty(), then if its length equals capacity, otherwise it has space.
