Jameo Core Library
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
jm::Stack< T > Class Template Reference

This class provides a stack container that processes data elements based on the "Last in - First out" principle. More...

Public Member Functions

 Stack ()
 Constructor for the stack. Initializes all variables.
 
 ~Stack ()
 Destructor for the stack. Here all variables are deleted.
 
bool hasElements () const
 This method returns true if the stack is not empty.
 
pop ()
 Removes and returns the top element from the stack.
 
T & top () const
 Returns the top element of the stack without removing it.
 
T * topRef ()
 Returns the top element of the stack without removing it.
 
top2 ()
 Returns the second top element of the stack without removing it.
 
top3 ()
 Returns the third element from the top of the stack without removing it.
 
void push (T data)
 Adds an element to the stack.
 
void clear ()
 Deletes all elements on the stack.
 
size_t size () const
 Returns the number of elements on the stack.
 
void reverse ()
 Reverses the order of the stack. The bottom element becomes the top.
 

Detailed Description

template<class T>
class jm::Stack< T >

This class provides a stack container that processes data elements based on the "Last in - First out" principle.

The Stack class allows elements to be added and removed from the top of the stack, maintaining the order in which they were added.

Template Parameters
TThe type of data elements stored in the stack.

Constructor & Destructor Documentation

◆ Stack()

template<class T >
jm::Stack< T >::Stack ( )
inline

Constructor for the stack. Initializes all variables.

◆ ~Stack()

template<class T >
jm::Stack< T >::~Stack ( )
inline

Destructor for the stack. Here all variables are deleted.

Member Function Documentation

◆ clear()

template<class T >
void jm::Stack< T >::clear ( )
inline

Deletes all elements on the stack.

◆ hasElements()

template<class T >
bool jm::Stack< T >::hasElements ( ) const
inline

This method returns true if the stack is not empty.

◆ pop()

template<class T >
T jm::Stack< T >::pop ( )
inline

Removes and returns the top element from the stack.

Returns
The top element of the stack.

◆ push()

template<class T >
void jm::Stack< T >::push ( data)
inline

Adds an element to the stack.

Parameters
dataThe data to be added to the stack.

◆ reverse()

template<class T >
void jm::Stack< T >::reverse ( )
inline

Reverses the order of the stack. The bottom element becomes the top.

◆ size()

template<class T >
size_t jm::Stack< T >::size ( ) const
inline

Returns the number of elements on the stack.

Returns
The number of elements on the stack.

◆ top()

template<class T >
T & jm::Stack< T >::top ( ) const
inline

Returns the top element of the stack without removing it.

Returns
The top element of the stack.

◆ top2()

template<class T >
T jm::Stack< T >::top2 ( )
inline

Returns the second top element of the stack without removing it.

Returns
The second top element of the stack.

◆ top3()

template<class T >
T jm::Stack< T >::top3 ( )
inline

Returns the third element from the top of the stack without removing it.

Returns
The third element from the top of the stack.

◆ topRef()

template<class T >
T * jm::Stack< T >::topRef ( )
inline

Returns the top element of the stack without removing it.

Returns
The top element of the stack.