Class PreOrderSearch<T>
java.lang.Object
io.openml.gearbox.binarytree.traversal.AbstractVisitor<T,R>
io.openml.gearbox.binarytree.traversal.AbstractPreOrderVisitor<T,Optional<TreeNode<T>>>
io.openml.gearbox.binarytree.traversal.PreOrderSearch<T>
- Type Parameters:
T
- The type of the value/data being searched as well as being stored in each node of the binary tree being searched
Deprecated.
Performs pre-order search on a binary tree for a target value.
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
Deprecated.Returns whether or not the traversal should terminate early and callAbstractVisitor.getTraversalResult()
right after.Deprecated.Searches for a node with a target value in a binary tree and returns that node.forValue
(T target) Deprecated.Creates a search instance for a specifiedtree node value
.Deprecated.Returns the final result computed after visiting tree (either all-node visit or partial visit)protected void
Deprecated.Performs actions on each visited node during traversal.Methods inherited from class io.openml.gearbox.binarytree.traversal.AbstractPreOrderVisitor
apply, traverse
-
Method Details
-
forValue
Deprecated.Creates a search instance for a specifiedtree node value
.- Type Parameters:
T
- The type of the value/data stored in each node of the binary tree being searched- Parameters:
target
- The value of the tree node, which is to be found- Returns:
- a new instance
- Throws:
NullPointerException
- iftarget
isnull
-
doSearch
Deprecated.Searches for a node with a target value in a binary tree and returns that node.More formally, the target node whose
node value
is equal to the target value, determined byObject.equals(Object)
, is returned.This method runs in O(n) time and O(n) space without recursion.
- Parameters:
root
- The root of the binary tree- Returns:
- the node with the target value wrapped inside
Optional
orOptional.empty()
if no such node is found - Throws:
NullPointerException
- ifroot
isnull
-
getTraversalResult
Deprecated.Description copied from class:AbstractVisitor
Returns the final result computed after visiting tree (either all-node visit or partial visit)For example, this method can return the max node value of entire tree after iterating through all tree nodes.
- Specified by:
getTraversalResult
in classAbstractVisitor<T,
Optional<TreeNode<T>>> - Returns:
- object computed by a complete or partial traversal
-
visitNode
Deprecated.Description copied from class:AbstractVisitor
Performs actions on each visited node during traversal. -
canTerminate
protected boolean canTerminate()Deprecated.Description copied from class:AbstractVisitor
Returns whether or not the traversal should terminate early and callAbstractVisitor.getTraversalResult()
right after.For example, this could be useful while searching a tree for a target
1 / \ 2 3 / \ \ 4 5 6
Suppose we are searching for node 2 in the tree above.AbstractVisitor.canTerminate()
can be implemented asif (node.value == 2) { return true } else { return false }
- Specified by:
canTerminate
in classAbstractVisitor<T,
Optional<TreeNode<T>>> - Returns:
true
if traversal result is already publishable.
-
PreOrderSearch
reflects an obsolete implementation that doesn't strictly bind the principle of Visitor pattern. Please use the enhancedTreeTraverser