AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Stack: Infix nach Postfix und push und pop

Ein Thema von Luckie · begonnen am 14. Mär 2010 · letzter Beitrag vom 20. Mär 2010
Antwort Antwort
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.378 Beiträge
 
Delphi 12 Athens
 
#1

Re: Stack: Infix nach Postfix und push und pop

  Alt 18. Mär 2010, 23:10
Dabei macht der Code doch eigentlich nichts Anderes?
Außer daß die Schittstellen der Ein- und Ausgabe umgestellt wurde.

Statt READ wird jetzt nacheinander ein Zeichen aus dem String genommen
und anstatt WRITE wird der Text an den Result-String angehängt.
OK, für ein nachfolgendes EOL wird nun vorher die aktuelle Zeichenpostition über LENGTH geprüft.

// dein Code aus Post #1
{} nachfolgend jeweils der entsprechende Befehl aus Pst #10

Delphi-Quellcode:
function Infix2Postfix(const S: String): String;
var
  i: Integer;
begin
  Result := '';
//Init;
{}init;
//repeat
{}i := 1;
{}while i <= Length(S) do begin
  //repeat read(c) until c <> ' ';
  {}if S[i] <> ' then begin
    //if c = ')' then write(chr(pop));
    {}if S[i] = ')then Result := Result + chr(pop);
    //if c = '+' then push(ord(c));
    {}if S[i] = '+then push(ord(S[i]));
    //if c = '*' then push(ord(c));
    {}if S[i] = '*then push(ord(S[i]));
    //while (c >='0') and (c<='9') do
    // begin write(c), read(c); end;
    {}if (S[i] >= '0') and (S[i] <= '9') then begin
    {}  Result := Result + S[i];
    {}  while (i < Length(S)) and (S[i + 1] >= '0') and (S[i + 1] <= '9') do begin
    {}    Result := Result + S[i];
    {}    Inc(i);
    {}  end;
    {}end;
    //if c <> '(' then write (' ');
    {}if (i <= Length(S)) and (S[i] <> '(') then Result := Result + ' ';
  {}end;
//until eoln;
{}  Inc(i);
{}end;
end;

function CalcPostfix(const S: String): String;
var
  i, x: Integer;
begin
  Result := '';
//Init;
{}init;
//repeat
{}i := 1;
{}while i <= Length(S) do begin
  //x := 0;
  //repeat read(c) until c <> ' ';
  {}if S[i] <> ' then begin
  {}  x := 0;
    //if c = '*' then x := pop*poop;
    {}if S[i] = '*then x := pop * pop;
    //if c = '+' then x := pop+pop;
    {}if S[i] = '+then x := pop + pop;
    //while (c >= '0') and (c <= '9') do
    //begin
    // x := 10*x+(ord(c)-ord('0'));
    // read(c);
    //end;
    {}if (S[i] >= '0') and (S[i] <= '9') then begin
    {}  x := ord(S[i]) - ord('0');
    {}  while (i < Length(S)) and (S[i + 1] >= '0') and (S[i + 1] <= '9') do begin
    {}    x := 10 * x + (ord(S[i]) - ord('0'));
    {}    Inc(i);
    {}  end;
    {}end;
    //push(x);
    {}push(x);
  {}end;
//until eoln;
{}  Inc(i);
{}end;
//writeln(pop);
{}Result := Result + IntToStr(pop);
end;
Ein Therapeut entspricht 1024 Gigapeut.
  Mit Zitat antworten Zitat
Antwort Antwort


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:45 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz