Skip to main content

getNewBBSTree

Short summary

This method can be used to dynamically create a __NEW binary balanced search tree.

Return: SingleExecutionResult.SUCCESS: allocation succesful, output tree contains new tree instance SingleExecutionResult.ERROR: error during allocation, output tree is NULL

Parameters

NameTypeCommentKind
comparatorCNM_AbstractObject.IComparatoroptional custom comparatorinput
treeCNM_CollectionInterfaces.IBalancedBinarySearchTreethe created treeoutput

Code

Declaration

METHOD getNewBBSTree :CNM_ReturnTypes.SingleExecutionResult
VAR_INPUT
(*optional custom comparator*)
comparator : CNM_AbstractObject.IComparator := 0;
END_VAR
VAR_OUTPUT
(* the created tree *)
tree :CNM_CollectionInterfaces.IBalancedBinarySearchTree;
END_VAR
VAR
newBalancedBinarySearchTree :POINTER TO BalancedBinarySearchTree;
END_VAR
VAR CONSTANT
OBJECT_NOT_REFERENCED :__XWORD := 0;
END_VAR

Implementation

getNewBBSTree := CNM_ReturnTypes.SingleExecutionResult.ERROR;
IF THIS^.isObjectValid(comparator) THEN
newBalancedBinarySearchTree := __NEW(
BalancedBinarySearchTree(nodeComparator := comparator)
);
ELSE
newBalancedBinarySearchTree := __NEW(
BalancedBinarySearchTree(nodeComparator := OBJECT_NOT_REFERENCED)
);
END_IF

IF (newBalancedBinarySearchTree <> 0) THEN
tree := newBalancedBinarySearchTree^;
getNewBBSTree := CNM_ReturnTypes.SingleExecutionResult.SUCCESS;
END_IF