Autor Beitrag
Bestzeller
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 48



BeitragVerfasst: Mo 08.06.09 20:07 
Hi,
Wie schon im Titel genannt, hab ich eine Endlosschleife die eigentlich nicht dar sein dürfte,
da exponent = 0.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
function TBaum.potenz(basis:Integer;exponent:Integer):Integer;
 VAR ergebnis:Integer;
begin
  If exponent = 0 then result:=1;
  if exponent = 1 then result:=basis else
  begin
    if exponent mod 2 = 0 then
    begin
      ergebnis:=potenz(basis, exponent div 2);
      result:=ergebnis*ergebnis;//Bis Hier
    end else 
      result:=potenz(basis, exponent-1)*basis;
  end;
end;

Ich hab es schon mit dem Debugger überprüft und für exponent wird auch 0 übergeben und für basis 1 ,
aber irgentwie läuft das Programm trotzdem weiter bis dar, wo bis hier steht. Und nachher gibt es einen Stack-=Overflow.
oki
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40

Win XP
Delphi 2007 Prof
BeitragVerfasst: Mo 08.06.09 20:19 
Deine 2. If-Anweisungen ist für den else-Zweig auch gültig, wenn Exponent = 0 ist.

Gruß oki

_________________
42
Bestzeller Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 48



BeitragVerfasst: Mo 08.06.09 20:33 
Thx oki. Hab vergessen das Delphi trotzdem noch weiter schaut.