Files
hello-algo/ru/codes/rust/chapter_stack_and_queue/stack.rs
Yudong Jin 772183705e Add ru version (#1865)
* Add Russian docs site baseline

* Add Russian localized codebase

* Polish Russian code wording

* Update ru code translation.

* Update code translation and chapter covers.

* Fix pythontutor extraction.

* Add README and landing page.

* placeholder of profiles

* Use figures of English version

* Remove chapter paperbook
2026-03-28 04:24:07 +08:00

41 lines
1.2 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* File: stack.rs
* Created Time: 2023-02-05
* Author: codingonion (coderonion@gmail.com)
*/
use hello_algo_rust::include::print_util;
/* Driver Code */
pub fn main() {
// Инициализировать стек
// В Rust рекомендуется использовать Vec как стек
let mut stack: Vec<i32> = Vec::new();
// Помещение элемента в стек
stack.push(1);
stack.push(3);
stack.push(2);
stack.push(5);
stack.push(4);
print!("Стек stack = ");
print_util::print_array(&stack);
// Доступ к верхнему элементу стека
let peek = stack.last().unwrap();
print!("\nВерхний элемент peek = {peek}");
// Извлечение элемента из стека
let pop = stack.pop().unwrap();
print!("\nИзвлеченный элемент pop = {pop}, stack после извлечения = ");
print_util::print_array(&stack);
// Получение длины стека
let size = stack.len();
print!("\nДлина стека size = {size}");
// Проверка, пуст ли стек
let is_empty = stack.is_empty();
print!("\nПуст ли стек = {is_empty}");
}