SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Sleak::Stack< T > Class Template Reference

Implements a LIFO (Last-In, First-Out) stack data structure. More...

#include <Stack.hpp>

Public Member Functions

 Stack ()=default
void clear ()
bool isEmpty () const
void pop ()
 Removes the top element; throws if empty.
void push (const T &value)
 Pushes value onto the top of the stack.
size_t size () const
T & top ()
 Top element without removing it; throws if empty.
const T & top () const

Detailed Description

template<typename T>
class Sleak::Stack< T >

Implements a LIFO (Last-In, First-Out) stack data structure.

The Stack class maintains a collection of elements with the most recently added element at the top. It is suitable for scenarios where you need to process elements in a last-come, first-served manner. Use this class when you need to implement function call stacks, expression evaluation, or depth-first search algorithms.

Example Use Cases:

  • Implementing a function call stack in a compiler or interpreter.
  • Evaluating arithmetic expressions with parentheses.
  • Performing depth-first search in graph algorithms.
  • Implementing undo/redo functionality in an editor.

Implementation Details:

  • Uses an underlying List to store the stack elements.
  • Provides methods for pushing (adding) and popping (removing) elements.
  • Maintains the LIFO order of elements.

Definition at line 30 of file Stack.hpp.

Constructor & Destructor Documentation

◆ Stack()

template<typename T>
Sleak::Stack< T >::Stack ( )
default

Member Function Documentation

◆ clear()

template<typename T>
void Sleak::Stack< T >::clear ( )
inline

Definition at line 76 of file Stack.hpp.

◆ isEmpty()

template<typename T>
bool Sleak::Stack< T >::isEmpty ( ) const
inline

Definition at line 68 of file Stack.hpp.

◆ pop()

template<typename T>
void Sleak::Stack< T >::pop ( )
inline

Removes the top element; throws if empty.

Definition at line 40 of file Stack.hpp.

◆ push()

template<typename T>
void Sleak::Stack< T >::push ( const T & value)
inline

Pushes value onto the top of the stack.

Definition at line 35 of file Stack.hpp.

◆ size()

template<typename T>
size_t Sleak::Stack< T >::size ( ) const
inline

Definition at line 72 of file Stack.hpp.

◆ top() [1/2]

template<typename T>
T & Sleak::Stack< T >::top ( )
inline

Top element without removing it; throws if empty.

Definition at line 54 of file Stack.hpp.

◆ top() [2/2]

template<typename T>
const T & Sleak::Stack< T >::top ( ) const
inline

Definition at line 61 of file Stack.hpp.