1namespace StackImplementation
3 internal class Stack<T>
6 private const int Capacity = 4;
7 private readonly T[] _stack = new T[Capacity];
14 private bool IsEmpty()
20 return _top == Capacity - 1;
25 System.Console.WriteLine(!IsEmpty() ? $"The topmost element is: {_stack[_top]}" : "The stack is empty.");
30 return !IsEmpty() ? _stack[_top--] : default;
33 public void Push(T element)
37 _stack[++_top] = element;
41 System.Console.WriteLine("Cannot push - the stack is full.");
45 public override string ToString()
49 return "The stack is empty.";
54 for (var index = 0; index < _top; index++)
56 depiction += _stack[index].ToString() + ' ';
59 depiction += _stack[_top].ToString();
61 return $"Stack: [{depiction}]";
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list