Junior — Middle
Kas saaksite selgitada andmestruktuuri virna tööpõhimõtet?
sobes.tech AI
Vastus AI-lt
Stack is a data structure that operates on the LIFO (Last In, First Out) principle, meaning the last inserted element is the first to be removed.
Main operations of the stack:
- push — add an element to the top of the stack;
- pop — remove and return the top element;
- peek (or top) — view the top element without removing it.
Example: if you sequentially put elements 1, 2, 3 into the stack, when removing, 3 will come out first, then 2, and finally 1.
Stacks are widely used for implementing function calls, undo actions, expression parsing, etc.