Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
i have a recursive function "iselement" given which determines in a binary tree the number of nodes in which the info- component is larger or equal a
In detail it looks as follows.
tnat = 0..maxint;
trefbintree = ^tbintree;
tbintree = record
info : integer;
right : trefbintree
function iselement(inrefroot : trefbintree; invalue : integer) : tnat;
number : tnat;
if inrefroot = nil then
number := 0
number := iselement(inrefroot^.right, invalue)
+ iselement(inrefroot^.left, invalue);
if inrefroot^.info >= invalue then
number := number + 1
iselement := number
Could anybody explain the steps in the recursion and why this code actually works?
Why cant I put the if- part "if inrefroot^.info >= invalue"
before the instruction
"number := iselement(...)+ iselement(...);"?
I would appreciate any help. Thank you
0 · ·