Einzelnen Beitrag anzeigen

Benutzerbild von JasonDX
JasonDX
(CodeLib-Manager)

Registriert seit: 5. Aug 2004
Ort: München
1.062 Beiträge
 
#11

Re: Thats Insane - wrong memory setting by recursion???

  Alt 20. Apr 2006, 22:43
Zitat von sk.Silvia:
ok but ist the same also when i put

Delphi-Quellcode:
function TBinTree.FindMin(init:boolean):integer;
      begin
      if init then result:=self.Value;
      //ShowMessage('val '+ValToStr+' res'+inttostr(result));
      if value<result then
        begin
        result:=value;
        end;

      if not(left=nil) then result:=left.FindMin(false);
      if not(right=nil) then result:=right.FindMin(false);
      end;
value is always inicializes and result now too, but why the result changes besides on ShowMessage (again it gives the right value when i dont hide the showmessage dialog)
Yea, because at the first call result will be initialized. But every recursive call after that does not initialize the result variable. You call the method with false as init-parameter, which tells not to initialize the variable. So once again: result is undefined

greetz
Mike
Mike
Passion is no replacement for reason
  Mit Zitat antworten Zitat