Data Structures in C++
Public Member Functions
DynamicStack< T > Class Template Reference

Stack implementation with dynamic memory allocation. More...

#include <DynamicStack.hpp>

Inheritance diagram for DynamicStack< T >:
Collaboration diagram for DynamicStack< T >:

Public Member Functions

 DynamicStack ()
 
 DynamicStack (T data[])
 create the structure and populate it with the data from the array More...
 
std::string getName ()
 Provides the name of the data structure as a string representation. More...
 
void push (T val)
 Add an element to the top of the stack. More...
 
pop ()
 Remove an element from the top of the stack. More...
 
peek ()
 See the value from the top of the stack, without removing it. More...
 
int getSize ()
 Outputs the number of elements stored in the structure. More...
 
bool isEmpty ()
 Check whether the structure is empty. More...
 
bool isFull ()
 Check whether the structure is full. More...
 
- Public Member Functions inherited from ProtectedLinkedList< T >
string getName ()
 Provides the name of the data structure as a string representation. More...
 
 ProtectedLinkedList ()
 
 ~ProtectedLinkedList ()
 
int getSize ()
 Outputs the number of elements stored in the structure. More...
 
bool isEmpty ()
 Check whether the structure is empty. More...
 
bool isFull ()
 Check whether the structure is full. More...
 
- Public Member Functions inherited from Stack< T >
std::string getName ()
 Provides the name of the data structure as a string representation. More...
 

Additional Inherited Members

- Protected Member Functions inherited from ProtectedLinkedList< T >
Node< T > * getNode (int index)
 
 ProtectedLinkedList (const T data[])
 create the structure and populate it with the data from the array More...
 
Node< T > * getFirst () const
 
Node< T > * getLast () const
 
virtual void insert (const T val)
 Insert an element at the end of the list. More...
 
virtual void insert (const T val, const int index)
 Insert an element at the specified position in the list. More...
 
virtual T remove (const int index)
 Remove an element from the list. More...
 
virtual T get (const int index)
 Get the element at the specified position in the list, without removing. More...
 
virtual Iterator< T > iterator ()
 Creates an Iterator, an object that allows the sequential access of values in a Linked List without the search overhead. More...
 

Detailed Description

template<class T>
class DynamicStack< T >

Stack implementation with dynamic memory allocation.

Author
Douglas De Rizzo Meneghetti (dougl.nosp@m.asri.nosp@m.zzom@.nosp@m.gmai.nosp@m.l.com)
Date
2017-6-14Stack implementation with dynamic memory allocation. This stack extends a ProtectedLinkedList in order to gain dynamic memory allocation powers.
Template Parameters
TThe type of object the data structure will contain

Definition at line 19 of file DynamicStack.hpp.

Constructor & Destructor Documentation

◆ DynamicStack() [1/2]

template<class T>
DynamicStack< T >::DynamicStack ( )
inlineexplicit

Definition at line 21 of file DynamicStack.hpp.

21 {}

◆ DynamicStack() [2/2]

template<class T>
DynamicStack< T >::DynamicStack ( data[])
inlineexplicit

create the structure and populate it with the data from the array

Parameters
dataan array with data with which the structure will be initialized

Definition at line 25 of file DynamicStack.hpp.

25 : ProtectedLinkedList<T>(data) {}
Doubly-linked list implementation with dynamic memory allocation.
<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD
Here is the call graph for this function:
=======
>>>>>>> 36f9b37... fixed dependency of ProtectedLinkedList to Iterator =======
>>>>>>> bded2143692dca559ffcc9e7202d9eb5fbfc45bf =======
>>>>>>> master

Member Function Documentation

◆ getName()

template<class T>
std::string DynamicStack< T >::getName ( )
inlinevirtual

Provides the name of the data structure as a string representation.

Returns
name of the data structure

Implements DataStructure.

Definition at line 27 of file DynamicStack.hpp.

27 { return "Dynamic Stack"; }

◆ getSize()

template<class T>
int DynamicStack< T >::getSize ( )
inlinevirtual

Outputs the number of elements stored in the structure.

Returns
number of elements stored in the structure

Implements DataStructure.

Definition at line 43 of file DynamicStack.hpp.

int getSize()
Outputs the number of elements stored in the structure.
Here is the caller graph for this function:

◆ isEmpty()

template<class T>
bool DynamicStack< T >::isEmpty ( )
inlinevirtual

Check whether the structure is empty.

Returns
True if empty, otherwise false

Implements DataStructure.

Definition at line 45 of file DynamicStack.hpp.

bool isEmpty()
Check whether the structure is empty.
<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD
Here is the call graph for this function:
=======
>>>>>>> 36f9b37... fixed dependency of ProtectedLinkedList to Iterator =======
>>>>>>> bded2143692dca559ffcc9e7202d9eb5fbfc45bf ======= >>>>>>> master

◆ isFull()

template<class T>
bool DynamicStack< T >::isFull ( )
inlinevirtual

Check whether the structure is full.

Returns
True if full, otherwise false

Implements DataStructure.

Definition at line 47 of file DynamicStack.hpp.

bool isFull()
Check whether the structure is full.
<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD
Here is the call graph for this function:
=======
>>>>>>> 36f9b37... fixed dependency of ProtectedLinkedList to Iterator =======
>>>>>>> bded2143692dca559ffcc9e7202d9eb5fbfc45bf ======= >>>>>>> master

◆ peek()

template<class T>
T DynamicStack< T >::peek ( )
inlinevirtual

See the value from the top of the stack, without removing it.

Returns
The value on the top of the stack

Implements Stack< T >.

Definition at line 37 of file DynamicStack.hpp.

37  {
38  if (isEmpty())
39  throw std::out_of_range("The stack is empty");
41  }
int getSize()
Outputs the number of elements stored in the structure.
bool isEmpty()
Check whether the structure is empty.
virtual T get(const int index)
Get the element at the specified position in the list, without removing.
Here is the call graph for this function:

◆ pop()

template<class T>
T DynamicStack< T >::pop ( )
inlinevirtual

Remove an element from the top of the stack.

Returns
the value that is being removed

Implements Stack< T >.

Definition at line 31 of file DynamicStack.hpp.

31  {
32  if (isEmpty())
33  throw std::out_of_range("The stack is empty");
35  }
int getSize()
Outputs the number of elements stored in the structure.
bool isEmpty()
Check whether the structure is empty.
virtual T remove(const int index)
Remove an element from the list.
Here is the call graph for this function:

◆ push()

template<class T>
void DynamicStack< T >::push ( val)
inlinevirtual

Add an element to the top of the stack.

Parameters
valthe value to be added to the stack

Implements Stack< T >.

Definition at line 29 of file DynamicStack.hpp.

int getSize()
Outputs the number of elements stored in the structure.
virtual void insert(const T val)
Insert an element at the end of the list.
Here is the call graph for this function:

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