Stack & queue
Në shqip: Stivë dhe radhë
ShpjegimiSQ
Stack-u (stiva) dhe queue-ja (radha) janë dy struktura të thjeshta të dhënash. Te stack-u, i fundit që hyn del i pari (LIFO); te queue-ja, i pari që hyn del i pari (FIFO). Butoni „Back“ i shfletuesit përdor një stack.
EnglishEN
A stack and a queue are two simple data structures. In a stack, the last item in is the first out (LIFO); in a queue, the first in is the first out (FIFO). The browser's “Back” button uses a stack.
Si ta mendosh
Stack-u është si pirgu i pjatave: merr gjithmonë atë sipër. Queue-ja është si radha te furra: shërbehet ai që erdhi i pari.
Lexoje në anglisht
A stack is like a pile of plates: you always take the top one. A queue is like the line at the bakery: whoever came first gets served first.
Shembull kodipython
stiva = [1, 2, 3]
stiva.pop() # 3 — i fundit del i pari
from collections import deque
radha = deque(["Arta", "Besnik"]); radha.popleft() # "Arta" — i pari del i pari