insert
Short summary
This method can be used to insert a single element into the tree. It will only be inserted if the tree does not already contain an equal element.
Return: SUCCESS: operation successful
ABORTED: object was already contained, null object was passed or the tree itself was passed
ERROR: container allocation failed or tree itself was inconsistent
- Return type: CNM_ReturnTypes.SingleExecutionResult
Parameters
| Name | Type | Comment | Kind |
|---|---|---|---|
| object | CNM_AbstractObject.IObject | The object that should be inserted | input |
Code
Declaration
METHOD INTERNAL insert :CNM_ReturnTypes.SingleExecutionResult
VAR_INPUT
(*The object that should be inserted*)
object :CNM_AbstractObject.IObject;
END_VAR
VAR
heightNotChanged :BOOL := TRUE;
returnedRoot :CNM_CollectionInterfaces.IBalancedBinarySearchTreeNode;
END_VAR
Implementation
insert := CNM_ReturnTypes.SingleExecutionResult.ABORTED;
RETURN(THIS^.isObjectNull(object) OR_ELSE THIS^.isEqual(object));
returnedRoot := THIS^.recursivInsert(
object := object,
elem := THIS^.rootNode,
heightNotChanged := heightNotChanged,
insertResult => insert
);
IF insert = CNM_ReturnTypes.SingleExecutionResult.SUCCESS THEN
THIS^.rootNode := returnedRoot;
THIS^.announceChange();
THIS^.incrementSize();
END_IF