Skip to main content

getInorderSuccessor

Short summary

finds the next greater node (inorder successor) of a specified node

Return: TRUE if inorder successor is found, FALSE else

  • Return type: BOOL

Parameters

NameTypeCommentKind
nodebufferPOINTER TO CNM_CollectionInterfaces.IBinaryTreeNode-inout
bufferindex__XWORD-inout
successorCNM_CollectionInterfaces.IBinaryTreeNodeif successor is found then successor, else nulloutput

Code

Declaration

METHOD PROTECTED getInorderSuccessor :BOOL

VAR_IN_OUT
nodebuffer :POINTER TO CNM_CollectionInterfaces.IBinaryTreeNode;
bufferindex :__XWORD;
END_VAR
VAR_OUTPUT
(*if successor is found then successor, else null*)
successor :CNM_CollectionInterfaces.IBinaryTreeNode;
END_VAR
VAR_INST
currentNode :CNM_CollectionInterfaces.IBinaryTreeNode;
END_VAR
VAR CONSTANT
OBJECT_NOT_REFERENCED :__XWORD := 0;
END_VAR

Implementation

IF THIS^.isObjectNull(currentNode) THEN
currentNode := nodebuffer[bufferindex];
nodebuffer[bufferindex] := OBJECT_NOT_REFERENCED;
dec(bufferindex);
END_IF
successor := currentNode;
getInorderSuccessor := THIS^.isObjectValid(currentNode) OR THIS^.isObjectValid(nodebuffer[bufferindex]);
IF THIS^.isObjectValid(currentNode) THEN
currentNode := THIS^.getSmallestNode(startNode := currentNode.rightChild,nodebuffer := nodebuffer, bufferindex := bufferindex);
END_IF