Ver Mensaje Individual
  #1  
Antiguo 06-04-2010
xeelons xeelons is offline
Registrado
 
Registrado: jul 2007
Posts: 4
Reputación: 0
xeelons Va por buen camino
Problema al implementar Pilas

Despues de 1 año de no haber programado en delphi tube problemas al tratar de implementar el algoritmo que transforma una cadena de numeros y operadores a otra, lo que es llamado de infija a posfija,no logro darme cuenta cuall es el problema , se los agradeceria si podrian ayudarme.

Gracias
Código Delphi [-]
program posfijaproject;



uses
  SysUtils,dialogs;
const
max=100;
type
 tipoelemento=char;
 pila=array[1..max]of tipoelemento;
var
 Pila;
 tope:0..max;
 x:char;
 infija,posfija:string;
 i:integer;

procedure CreaPila(var Pila);
  begin
  tope:=0;
  end;
function PilaVacia(Pila):boolean;
  begin
  PilaVacia:=(tope=0);
  end;
function Pilallena(Pila):boolean;
  begin
  Pilallena:=(tope=max);
  end;
procedure Apilar(Var Pila ; x:char);
  begin
  if Pilallena(P)
  then
  showmessage('La pila esta llena')
  else
    begin
    tope:=tope+1;
    P[tope]:=x;
    end;
  end;
procedure Desempilar(Var Pila ; x:char);
  begin
  if PilaVacia(P)
  then
  showmessage('la pila esta vacia')
  else
  begin
    x:=P[tope];
    tope:=tope-1;
  end;
  end;
procedure Accesatope(Pila);
  begin
    if not PilaVacia(P)
    then showmessage(P[tope]);
  end;

function Prioridad(var x:char):integer;
  var
  pri:integer;
  begin
      case x of
      '@':Prioridad:=3;
      '*':Prioridad:=2;
      '/':Prioridad:=2;
      '+':Prioridad:=1;
      '-':Prioridad:=1;
      '(':Prioridad:=0;
      ')':Prioridad:=0;
      '0'..'9':Prioridad:=0;
      else
        showmessage('operador invalido')
      end;
  end;



 begin
 infija:=inputbox('infija','','');
 CreaPila(P);
  i:=0;
    for i:=1 to length(infija) do
        begin
         showmessage(intTostr(i));

            case infija[i] of
                '0'..'9'osfija[i]:=infija[i];
                '('              :Apilar(P,infija[i]);
                ')':
                     begin
                     showmessage(infija[i]);
                        while P[tope]<>'(' do
                            begin
                            Desempilar(P,infija[i]);
                            posfija[i]:=infija[i];
                        end;
                     end;
                '@': Apilar(P,infija[i]);
                '-','+','*','/':
                        begin
                          while Prioridad(P[tope])>=Prioridad(infija[i]) do
                            begin
                            Desempilar(P,P[tope]);
                            posfija[i]:=P[tope];
                            end;
                          Apilar(P,infija[i]);
                        end;

            else
            showmessage('que paso')
            end;

    end;





 end.

Última edición por xeelons fecha: 06-04-2010 a las 20:16:08.
Responder Con Cita