AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Object-Pascal / Delphi-Language Delphi Thats Insane - wrong memory setting by recursion???
Thema durchsuchen
Ansicht
Themen-Optionen

Thats Insane - wrong memory setting by recursion???

Ein Thema von sk.Silvia · begonnen am 20. Apr 2006 · letzter Beitrag vom 20. Apr 2006
Antwort Antwort
Seite 2 von 2     12   
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, 21: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
marabu

Registriert seit: 6. Apr 2005
10.109 Beiträge
 
#12

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

  Alt 20. Apr 2006, 21:53
Hi Silvia,

you might want to try out this:

Delphi-Quellcode:
uses
  Math;

function TBinTree.FindMin: Integer;
var
  minLeft, minRight: Integer;
begin
  if Assigned(left)
    then minLeft := left.FindMin
    else minLeft := value;
  if Assigned(right)
    then minRight := right.FindMin
    else minRight := value;
  Result := MinIntValue(value, minLeft, minRight);
end;
Kind regards

marabu
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 2     12   


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:27 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz