lab_trees
Tempestuous Trees
|
A derived, templatized class for preorder traversal algorithms on trees. More...
#include <PreorderTraversal.h>
Public Member Functions | |
PreorderTraversal (typename BinaryTree< T >::Node *root) | |
Initializes a Preorder 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 one past the end of the traversal. More... | |
void | add (typename BinaryTree< T >::Node *&treeNode) |
Adds the children of the given node to the stack to be processed later The right child is added before the left child to ensure that the left is popped before the right, thus following the rules of preorder traversals. 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 |
A derived, templatized class for preorder traversal algorithms on trees.
Simulates an iterative traversal of a given tree using a stack and a given root node.
|
inline |
Initializes a Preorder TreeTraversal of a tree, with the traversal storing the tree's root.
root | The root node of the tree |
|
inlinevirtual |
Adds the children of the given node to the stack to be processed later The right child is added before the left child to ensure that the left is popped before the right, thus following the rules of preorder traversals.
treeNode | The subroot whose children should be added |
Implements TreeTraversal< T >.
|
inlinevirtual |
Returns an iterator for the traversal starting at the root node.
Important for the sake of looping through an iterator's contents.
Implements TreeTraversal< T >.
|
inlinevirtual |
Returns true if the traversal is empty.
Implements TreeTraversal< T >.
|
inlinevirtual |
Returns an iterator for the traversal one past the end of the traversal.
Important for the sake of looping through an iterator's contents.
Implements TreeTraversal< T >.
|
inlinevirtual |
Returns the current node in the traversal or NULL if the stack is empty.
Implements TreeTraversal< T >.
|
inlinevirtual |
Removes and returns the current node in the traversal.
Implements TreeTraversal< T >.