Skip to main content

destructNodeAndAllChilds

Short summary​

destructs / deepdestructs all nodes in the subtrees of a specified node and this node

Parameters​

NameTypeCommentKind
nodeCNM_CollectionInterfaces.IBinaryTreeNodethe node that should be destructed with all it's childsinput
destructNodeContentsBOOLif true also the node contents will be destructed, if false only the nodes will be destructedinput

Code​

Declaration​

METHOD PROTECTED destructNodeAndAllChilds
VAR_INPUT
(*the node that should be destructed with all it's childs*)
node :CNM_CollectionInterfaces.IBinaryTreeNode;
END_VAR
VAR_INPUT
(*if true also the node contents will be destructed, if false only the nodes will be destructed*)
destructNodeContents :BOOL;
END_VAR
VAR
child :CNM_CollectionInterfaces.IBinaryTreeNode;
END_VAR
VAR CONSTANT
OBJECT_NOT_REFERENCED :__XWORD := 0;
END_VAR

Implementation​

IF THIS^.isObjectNull(node) THEN
RETURN;
END_IF

IF THIS^.isObjectValid(node.leftChild) THEN
child := node.leftChild;
THIS^.destructNodeAndAllChilds(node := child, destructNodeContents := destructNodeContents);
node.leftChild := OBJECT_NOT_REFERENCED;
END_IF
IF THIS^.isObjectValid(node.rightChild) THEN
child := node.rightChild;
THIS^.destructNodeAndAllChilds(node := child, destructNodeContents := destructNodeContents);
node.rightChild := OBJECT_NOT_REFERENCED;
END_IF
IF destructNodeContents THEN
node.deepDestruct();
ELSE
node.destruct();
END_IF
THIS^.decrementSize();