برنامج يقوم بالتحويل من infix to postfix لا اعلم سبب الخطأ وهذه محاولاتي
خالص الشكر مقدما
unit unfrmIfxToPosfix;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Mask, RzEdit, RzButton, ExtCtrls, RzPanel;
type
TForm1 = class(TForm)
pnl1: TRzPanel;
edt1: TRzEdit;
edt2: TRzEdit;
btnadd1: TRzButton;
procedure btnaddClick(Sender: TObject);
procedure btnadd1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const
MAX = 50;
var
Form1: TForm1;
Stack : array [1..MAX] of Char;
top : Integer ;
// top := -1;
implementation
{$R *.dfm}
function pop () : Char;
var
a : char;
begin
a:=stack[top];
top := top -1;
Result := a;
end;
procedure push(item:Char);
begin
top := top +1;
stack[top]:=item;
end;
function operat(symbol:char) : Integer;
begin
if (symbol = '+') or (symbol = '-' ) then
Result := 2;
if (symbol = '*') or (symbol = '/') then
Result := 4;
if (symbol = '(') or (symbol = ')') then
Result:= 1 ;
end;
function isoperat(symbol:char) :Integer;
begin
if (symbol = '+') or (symbol = '-') or (symbol = '*') or (symbol = '/')
or (symbol = '(') or (symbol = ')') then
Result := 1;
if true then
Result := 0;
end;
procedure convirtip(infix : array of char ; postfix : array of Char);
var
i,j: Integer;
symbol :Char ;
begin
top := -1;
i :=0;
//symbol:= 0;
j:=0;
Stack [++top]:= '#';
for i := 0 to 20 do
begin
symbol := infix;
if (isoperat(symbol)=0) then
begin
postfix[j]:=symbol;
j:= j+1 ;
end;
if True then
begin
if(symbol = '(')then
push(symbol);
if(symbol=')') then
begin
while(stack [top]<> '(') do
begin
postfix[j]:=pop();
j := j+1 ;
end;
pop();
end;
if (operat(symbol) > operat(stack[top])) then
begin
push(symbol);
if True then
begin
while(operat(symbol) <= operat(stack[top])) do
begin
postfix[j]:=pop();
j := j+1;
end;
push(symbol);
end;
end;
end;
end ;
while (Stack[top] <> '#') do
begin
postfix[j]:=pop();
j := j+1;
end;
postfix[j]:= '#';
end;
procedure TForm1.btnadd1Click(Sender: TObject);
var
infix , postfix : array [1..20] of Char ;
i: Integer;
begin
for i := 0 to 20 do
infix := edt1.Text ;
edt2 := convirtip(infix , postfix);
end;
end