Skip to content

Latest commit

 

History

History
71 lines (43 loc) · 4.3 KB

traversal.md

File metadata and controls

71 lines (43 loc) · 4.3 KB

gmd: Binary tree traversal

Traversor

The binary tree traversor is a structure that allows the iteration and traversal of a binary tree structure. It satisfies the requirements of BidirectionalIterator.


Member type Definition
value_type (const) binary_tree::value_type
reference value_type &
pointer value_type *
iterator_category std::bidirectional_iterator_tag
difference_type std::ptrdiff_t

Traversors can be implicitly converted to their reverse and/or const counterparts using constructors. However const traversors cannot be converted to non-const traversors.

Note: For the remainder of the document, please consider traversor as the type of the current object and reverse_traversor its reverse counterpart.


# reverse_traversor reverse () const <>

Returns a reversed traversor to the same element in the container.

# bool operator() () const <>

Checks if the traversor is valid, returning true if it is; false otherwise.


# bool operator== (const binary_tree_traversor &tr) const <>
# bool operator!= (const binary_tree_traversor &tr) const <>

Checks if the traversor references the same element as tr.

Note: All four variants of binary_tree_traversor (traversor, reverse_traversor, const_traversor, const_reverse_traversor) are accepted.


# traversor & go_up () <>
# traversor & go_left () <>
# traversor & go_right () <>

Moves the traversor within the binary tree structure. Returns *this.

# traversor up () const <>
# traversor left () const <>
# traversor right () const <>

Returns a traversor referencing another element in the binary tree structure.


# traversor & go_prev () <>
# traversor & go_next () <>

Moves the traversor within the binary tree structure, following the in-order traversal formalization. Returns *this.

Note: Functions traversor.go_prev() and traversor.go_next() are equivalent to --traversor and ++traversor, respectively.

# traversor prev () const <>
# traversor next () const <>

Returns a traversor referencing the previous or next element in the binary tree structure, following the in-order traversal formalization.

Note: Functions traversor.prev() and traversor.next() are equivalent to std::prev(traversor) and std::next(traversor), respectively.