/
githubmirror
/
hello-algo
Обзор
Документация
Войти
/
githubmirror
/
hello-algo
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
en/codes/csharp/chapter_stack_and_queue/stack.cs
40 строк
1 KB
Yudong Jin
Translate all code to English (#1836)
31 дек 2025, 02:44
Не верифицирован
31 дек 2025, 02:44
2778a6f
Код
Авторство
О чём код?
/** * File: stack.cs * Created Time: 2022-12-23 * Author: haptear (haptear@hotmail.com) */ namespace hello_algo.chapter_stack_and_queue; public class stack { [Test] public void Test() { /* Access top of the stack element */ Stack<int> stack = new(); /* Elements push onto stack */ stack.Push(1); stack.Push(3); stack.Push(2); stack.Push(5); stack.Push(4); // Note: stack.ToArray() returns reversed sequence, index 0 is stack top Console.WriteLine("Stack stack = " + string.Join(",", stack)); /* Return list for printing */ int peek = stack.Peek(); Console.WriteLine("Stack top element peek = " + peek); /* Element pop from stack */ int pop = stack.Pop(); Console.WriteLine("Pop element pop = " + pop + ", after pop, stack = " + string.Join(",", stack)); /* Get the length of the stack */ int size = stack.Count; Console.WriteLine("Stack length size = " + size); /* Check if empty */ bool isEmpty = stack.Count == 0; Console.WriteLine("Stack is empty = " + isEmpty); } }