indiocolifa
November 4th, 2004, 10:51 PM
I've the following problem.
I've a binary search tree which is ordered by a "code" key (1,2,3...n). For each node, I must find the minimum number (suppose a field Z) in a linked list which contains pointer to subtrees in each node. Those minimums must go in a list I generate (but this is not relevant in what I want).
The problem is not with the data structures, which I defined properly, I think. But the problem is with the recursion, specifically with a variable defined inside the recursion procedure.
Since this must be written in Pascal, I will post code in this language :o
Just look...
procedure generateList( srcTree : TREE_A; lookupList : LIST; var destList : DLIST);
var
dlinf : DESTLISTINFO;
begin
// this tree is travelled in order
generateList (srcTree^.left, lookupList, destList);
lookupMinimum (srcTree^.info, lookupList, dlinf);
AddItemToDstList (destList, dlinf);
generateList (srcTree^.right, lookupList, destList);
end;
To resume the problem is that I must get a minimum from travelling the entire tree (and the subtrees which are on the lookupList list). The minimum is returned into the dlinf parameter, but I'm suspecting that when the backtracking starts, dlinf will not contain the minimum.
I've a binary search tree which is ordered by a "code" key (1,2,3...n). For each node, I must find the minimum number (suppose a field Z) in a linked list which contains pointer to subtrees in each node. Those minimums must go in a list I generate (but this is not relevant in what I want).
The problem is not with the data structures, which I defined properly, I think. But the problem is with the recursion, specifically with a variable defined inside the recursion procedure.
Since this must be written in Pascal, I will post code in this language :o
Just look...
procedure generateList( srcTree : TREE_A; lookupList : LIST; var destList : DLIST);
var
dlinf : DESTLISTINFO;
begin
// this tree is travelled in order
generateList (srcTree^.left, lookupList, destList);
lookupMinimum (srcTree^.info, lookupList, dlinf);
AddItemToDstList (destList, dlinf);
generateList (srcTree^.right, lookupList, destList);
end;
To resume the problem is that I must get a minimum from travelling the entire tree (and the subtrees which are on the lookupList list). The minimum is returned into the dlinf parameter, but I'm suspecting that when the backtracking starts, dlinf will not contain the minimum.