Sobes.tech
Junior — Middle

Kas saaksite selgitada, mida mõistetakse virna kontseptsioonina programmeerimises?

sobes.tech AI

Vastus AI-lt

Stack is a data structure that operates on the LIFO (Last In, First Out) principle, meaning the last added element is the first to be removed.

Main operations with a stack:

  • push — add an element to the top of the stack;
  • pop — remove and return the top element;
  • peek (top) — view the top element without removing it.

Example in C#:

Stack<int> stack = new Stack<int>();
stack.Push(1);
stack.Push(2);
int top = stack.Pop(); // top = 2

Stacks are widely used for managing function calls, undo actions, traversing graphs, and other tasks.