Data Structures Class Templates
Various data structures implemented using c++ class templates.
|
Class template for stack data type. More...
#include <stack.h>
Public Member Functions | |
Stack (size_t s=10) | |
Constructor. More... | |
~Stack () | |
Destructor. More... | |
void | push (T value) |
Member function to push data into the stack. More... | |
T | pop () |
Member function which removes and returns element at the top of the stack. More... | |
T | stacktop () |
Member function which returns element at top of the stack. More... | |
bool | isEmpty () |
Member function for checking if stack is empty. More... | |
void | display () |
Member function for displaying the stack. More... | |
Class template for stack data type.
Class template for stack data type which can accept any type of data. Size of the stack is fixed once set in the constructor.
Constructor.
Creates a stack of size s. The stack size is fixed after constructing!
s | size_t parameter for setting the size of the stack, it takes default value of 10. |
Destructor.
It deletes the array and resets member variables to default values.
void Stack< T >::display |
Member function for displaying the stack.
Displays the stack vertically, i.e., from the stack top to the bottom, one below the another.
bool Stack< T >::isEmpty | ( | ) |
Member function for checking if stack is empty.
T Stack< T >::pop |
Member function which removes and returns element at the top of the stack.
Throws StackUnderflowError exception if run on an empty stack.
void Stack< T >::push | ( | T | value | ) |
Member function to push data into the stack.
Throws StackOverflowError exception if run on a full stack.
value | The data which is to be added to the stack. |
T Stack< T >::stacktop |
Member function which returns element at top of the stack.
Throws StackUnderflowError exception if run on an empty stack.