Data Structures Class Templates
Various data structures implemented using c++ class templates.
Public Member Functions | List of all members
Stack< T > Class Template Reference

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...
 
pop ()
 Member function which removes and returns element at the top of the stack. More...
 
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...
 

Detailed Description

template<typename T>
class Stack< T >

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 & Destructor Documentation

◆ Stack()

template<typename T >
Stack< T >::Stack ( size_t  s = 10)

Constructor.

Creates a stack of size s. The stack size is fixed after constructing!

Parameters
ssize_t parameter for setting the size of the stack, it takes default value of 10.

◆ ~Stack()

template<typename T >
Stack< T >::~Stack

Destructor.

It deletes the array and resets member variables to default values.

Member Function Documentation

◆ display()

template<typename T >
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.

◆ isEmpty()

template<typename T >
bool Stack< T >::isEmpty ( )

Member function for checking if stack is empty.

Returns
true if stack is empty, else returns false.

◆ pop()

template<typename T >
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.

Returns
Removes and returns element at top of stack by value.

◆ push()

template<typename T >
void Stack< T >::push ( value)

Member function to push data into the stack.

Throws StackOverflowError exception if run on a full stack.

Parameters
valueThe data which is to be added to the stack.

◆ stacktop()

template<typename T >
T Stack< T >::stacktop

Member function which returns element at top of the stack.

Throws StackUnderflowError exception if run on an empty stack.

Returns
The element at the top of the stack by value, does not remove.

The documentation for this class was generated from the following files: