Reference Guide: Pre/Post/Level Order Tree Iterators

In accordance to Standard Tree documentation, API allows following iteration methods:

Whenever a node is visited, a visit method of TreeNodeVisitor instance, already provided to function as argument, is executed. If it returns true iteration continues, otherwise it stops. Since TreeNodeVisitor is an interface, end users will need to provide an implementation for it.

PreOrderTreeIterator

Function that implements pre-order Standard Tree iteration from start node

Signature

template <typename T, int (*compare)(const T&, const T&) = comparator<T>, std::size_t (*hash)(const T&) = hash<T>> inline void PreOrderTreeIterator(TreeNode<T,compare,hash>* const& node, TreeNodeVisitor<T>* const& visitor)

PostOrderTreeIterator

Function that implements post-order Standard Tree iteration from start node

Signature

template <typename T, int (*compare)(const T&, const T&) = comparator<T>, std::size_t (*hash)(const T&) = hash<T>> inline void PostOrderTreeIterator(TreeNode<T,compare,hash>* const& node, TreeNodeVisitor<T>* const& visitor)

LevelOrderTreeIterator

Function that implements level-order Standard Tree iteration from start node with limitless depth

Signature

template <typename T, int (*compare)(const T&, const T&) = comparator<T>, std::size_t (*hash)(const T&) = hash<T>> inline void LevelOrderTreeIterator(TreeNode<T,compare,hash>* const& root, TreeNodeVisitor<T>* const& visitor)

Function that implements level-order Standard Tree iteration from start node with limited depth

Signature

template <typename T, int (*compare)(const T&, const T&) = comparator<T>, std::size_t (*hash)(const T&) = hash<T>> inline void LevelOrderTreeIterator(TreeNode<T,compare,hash>* const& root, std::size_t depth, TreeNodeVisitor<T>* const& visitor)

TreeNodeVisitor

Interface that defines prototype of a node visitor while Standard Tree iteration is performed

Signature

template <typename T, int (*compare)(const T&, const T&) = comparator<T>, std::size_t (*hash)(const T&) = hash<T>> class TreeNodeVisitor

Methods

Method Signature Description
~TreeNodeVisitor virtual ~TreeNodeVisitor () Deallocates internals from heap memory
visit virtual bool visit (TreeNode<T,compare,hash>* const& element) = 0 Visits a node during iteration. If false is returned, iteration stops!

Share