function IsItABinarySearchTree(t:BinaryTree): TAnswer; // the data type that is received // has a binary tree struct. // ie t^.data is root // t^.left.data is left sub tree node // t^.right.data is right sub tree node // for a binary search tree values must be smallest on sub tree nodes on LEFT var ans: TAnswer; arr : array of integer; begin (* each node from left <= right node *) ans.known := true; (* set to true *) arr := nil; // like to declare incase of random values! // no need for root node to check this, i to make sure the trees keep the arr[0] := t^.data; //root not needed for this one arr[1] := t^.left.data; arr[2] := t^.right.data; arr[3] := t^.left.left.data; arr[4] := t^.left.right.data; arr[5] := t^.right.left.data; arr[6] := t^.right.right.data; // check if left values are smaller to right // if they are all in order from left to right then OK if ((arr[1] <= arr[2]) AND (arr[3] <= arr[4]) AND (arr[4] <= arr[5]) AND (arr[5] <= arr[6])) then begin ans.answer := TRUE; ans.feedback := 'It Is A ...'; end else begin ans.answer := FALSE; ans.feedback := 'It is not A'; end; IsItABinarySearchTree := ans; (*return this*) end;