lab_trees
Tempestuous Trees
InorderTraversal< T > Class Template Reference

A derived, templatized class for inorder traversal algorithms on trees. More...

#include <InorderTraversal.h>

Inheritance diagram for InorderTraversal< T >:
[legend]
Collaboration diagram for InorderTraversal< T >:
[legend]

Public Member Functions

 InorderTraversal (typename BinaryTree< T >::Node *root)
 Initializes a Inorder TreeTraversal of a tree, with the traversal storing the tree's root. More...
 
TreeTraversal< T >::Iterator begin ()
 Returns an iterator for the traversal starting at the root node. More...
 
TreeTraversal< T >::Iterator end ()
 Returns an iterator for the traversal pointing to the element one past the end of the traversal. More...
 
void add (typename BinaryTree< T >::Node *&treeNode)
 Given a node in the tree, add the next appropriate nodes to the stack such that when popped, and inorder traversal is simulated. More...
 
BinaryTree< T >::Node * pop ()
 Removes and returns the current node in the traversal. More...
 
BinaryTree< T >::Node * peek () const
 Returns the current node in the traversal or NULL if the stack is empty. More...
 
bool empty () const
 Returns true if the traversal is empty. More...
 

Private Attributes

std::stack< typename BinaryTree< T >::Node * > stack
 
BinaryTree< T >::Node * root
 

Detailed Description

template<typename T>
class InorderTraversal< T >

A derived, templatized class for inorder traversal algorithms on trees.

Simulates an iterative traversal of a given tree using a stack and a given root node.

Constructor & Destructor Documentation

◆ InorderTraversal()

template<typename T >
InorderTraversal< T >::InorderTraversal ( typename BinaryTree< T >::Node *  root)
inline

Initializes a Inorder TreeTraversal of a tree, with the traversal storing the tree's root.

Hint: See lab handout for guidance

Parameters
rootThe root node of the tree

Member Function Documentation

◆ add()

template<typename T >
void InorderTraversal< T >::add ( typename BinaryTree< T >::Node *&  treeNode)
inlinevirtual

Given a node in the tree, add the next appropriate nodes to the stack such that when popped, and inorder traversal is simulated.

Hint: See lab handout for guidance

Parameters
treeNodeThe subroot that determines what next nodes should be added to the traversal

Implements TreeTraversal< T >.

◆ begin()

template<typename T >
TreeTraversal<T>::Iterator InorderTraversal< T >::begin ( )
inlinevirtual

Returns an iterator for the traversal starting at the root node.

Important for sake of looping through an iterator's contents.

Returns
The iterator object pointing to the first node in the traversal

Implements TreeTraversal< T >.

◆ empty()

template<typename T >
bool InorderTraversal< T >::empty ( ) const
inlinevirtual

Returns true if the traversal is empty.

Returns
true if the traversal is empty.

Implements TreeTraversal< T >.

◆ end()

template<typename T >
TreeTraversal<T>::Iterator InorderTraversal< T >::end ( )
inlinevirtual

Returns an iterator for the traversal pointing to the element one past the end of the traversal.

Important for the sake of looping through an iterator's contents

Returns
The iterator object pointing to the elemnt after the end of the traversal.

Implements TreeTraversal< T >.

◆ peek()

template<typename T >
BinaryTree<T>::Node* InorderTraversal< T >::peek ( ) const
inlinevirtual

Returns the current node in the traversal or NULL if the stack is empty.

Returns
The current node in the traversal

Implements TreeTraversal< T >.

◆ pop()

template<typename T >
BinaryTree<T>::Node* InorderTraversal< T >::pop ( )
inlinevirtual

Removes and returns the current node in the traversal.

Returns
The current node in the traversal

Implements TreeTraversal< T >.


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