Stos
Struktura LIFO, gdzie ostatni dodany element jest usuwany pierwszy.
A stack is an abstract data type that serves as a collection of elements with two principal operations: 'push' (adds an element) and 'pop' (removes the most recently added element). It is essential for managing function calls, undo mechanisms, and expression parsing.
graph LR
Center["Stos"]:::main
Rel_queue["queue"]:::related -.-> Center
click Rel_queue "/terms/queue"
Rel_array["array"]:::related -.-> Center
click Rel_array "/terms/array"
classDef main fill:#7c3aed,stroke:#8b5cf6,stroke-width:2px,color:white,font-weight:bold,rx:5,ry:5;
classDef pre fill:#0f172a,stroke:#3b82f6,color:#94a3b8,rx:5,ry:5;
classDef child fill:#0f172a,stroke:#10b981,color:#94a3b8,rx:5,ry:5;
classDef related fill:#0f172a,stroke:#8b5cf6,stroke-dasharray: 5 5,color:#94a3b8,rx:5,ry:5;
linkStyle default stroke:#4b5563,stroke-width:2px;
🧠 Sprawdzenie wiedzy
1 / 1
🧒 Wyjaśnij jak 5-latkowi
Wyobraź sobie stos naleśników. Kładziesz nowego na górę i zjadasz tego z góry jako pierwszego. Ostatni położony jest pierwszym zjedzonym!
🤓 Expert Deep Dive
Przepełnienie stosu (Stack Overflow) to klasyczny błąd rekurysji. Optymalizacja ogonowa (TCO) pozwala na nieskończoną rekurencję bez wzrostu stosu. Stosy bezblokadowe (Treiber) używają instrukcji CAS dla wielowątkowości.