Ver Mensaje Individual
  #3  
Antiguo 16-04-2009
Avatar de MaMu
MaMu MaMu is offline
Miembro
 
Registrado: abr 2006
Ubicación: Argentina
Posts: 863
Reputación: 19
MaMu Va por buen camino
Cita:
Empezado por Delphius Ver Mensaje
Hola MaMu,
Creo que para lo que buscas es muy buena idea optar por notación polaca inversa.
Me parece exelente. Pero la verdad, me maree un poco:

Código Delphi [-]
const 
  Abre = '(';
  Cierra = ')';
 
//(1+2)+4*(5+2)
function RPNCalculo(Calculo : String) : Boolean;
var
  nPos, nCalc, Resultado: Integer;
  StrChar: Char;
  Pila : TStringList;
  UltimaOperacion : String;
begin
  result := false;
  Pila := TStringList.Create;
  for nPos := 1 to Length(Calculo) do
  begin
    StrChar := Calculo[nPos];
    if StrChar in ['0','1','2','3','4','5','6','7','8','9'] then
    begin
      Pila.Add(StrChar);
      if (UltimaOperacion<>'') then
      begin
        Resultado := 0;
        for nCalc := 0 to Pila.Count -1 do
        begin
          Resultado := Resultado + StrToInt(Pila.Strings[nCalc]);
        end;
        Pila.Clear;
        Pila.Add(IntToStr(Resultado));
      end;
    end
    else if StrChar in [ABRE,CIERRA] then
    begin
    end
    else if StrChar in ['+','-','*','/'] then
    begin
      if Calculo[nPos + 1] in [ABRE,CIERRA] then
      begin
        UltimaOperacion := '';
      end  
      else UltimaOperacion := StrChar;
    end
    else
    begin
      UltimaOperacion := '';
    end;  
  end;
  Pila.Free;
end;

No se que hago mal, no doy pie con bola de la congestion.
Alguna ayuda????

Saludos y Muchas Gracias
__________________
Código Delphi [-]
 
try 
ProgramarMicro(80C52,'Intel',MnHex,True);
except
On Exception do
MicroChip.IsPresent(True);
end;
Responder Con Cita