mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 12:58:42 +08:00
Use Vec.last() method to access the top item of stack. (#942)
* Use Vec.last() method to access the top item of stack. * Use Vec.last() method to access the top item of stack.
This commit is contained in:
@ -22,7 +22,7 @@ pub fn main() {
|
||||
print_util::print_array(&stack);
|
||||
|
||||
// 访问栈顶元素
|
||||
let peek = stack.get(stack.len() - 1).unwrap();
|
||||
let peek = stack.last().unwrap();
|
||||
print!("\n栈顶元素 peek = {peek}");
|
||||
|
||||
// 元素出栈
|
||||
|
||||
Reference in New Issue
Block a user