getSmallestNode
Short summary
finds the smallest node in a specified (sub)tree
Return: the node with the smallest value based on the comparedTo Method
- Return type: CNM_CollectionInterfaces.IBinaryTreeNode
Parameters
| Name | Type | Comment | Kind |
|---|---|---|---|
| startNode | CNM_CollectionInterfaces.IBinaryTreeNode | the node from that the search should be started | input |
| nodebuffer | POINTER TO CNM_CollectionInterfaces.IBinaryTreeNode | - | inout |
| bufferindex | __XWORD | - | inout |
Code
Declaration
METHOD PROTECTED getSmallestNode :CNM_CollectionInterfaces.IBinaryTreeNode
VAR_INPUT
(*the node from that the search should be started*)
startNode :CNM_CollectionInterfaces.IBinaryTreeNode;
END_VAR
VAR_IN_OUT
nodebuffer :POINTER TO CNM_CollectionInterfaces.IBinaryTreeNode;
bufferindex :__XWORD;
END_VAR
VAR
currNode :CNM_CollectionInterfaces.IBinaryTreeNode;
END_VAR
VAR CONSTANT
OBJECT_NOT_REFERENCED :__XWORD := 0;
END_VAR
Implementation
IF THIS^.isObjectValid(startNode) THEN
currNode := startNode;
IF THIS^.isObjectValid(startNode.leftChild) THEN
IF THIS^.isObjectValid(nodebuffer[bufferindex]) THEN
inc(bufferindex);
END_IF
nodebuffer[bufferindex] := currNode;
inc(bufferindex);
currNode := currNode.leftChild;
ELSE
getSmallestNode := startNode;
RETURN;
END_IF
WHILE THIS^.isObjectValid(currNode.leftChild) DO
nodebuffer[bufferindex] := currNode;
currNode := currNode.leftChild;
inc(bufferindex);
END_WHILE
dec(bufferindex);
getSmallestNode := currNode;
RETURN;
ELSE
getSmallestNode := OBJECT_NOT_REFERENCED;
END_IF