Anda di halaman 1dari 2

Uses wincrt;

Const
Max = 10;
Var
Top,I : byte;
Pil,Temp, E : char;
Stack : array [1..Max] of Char;

Procedure PushAnim;
Begin
For I:=1 to 18 do
Begin
GotoXY(23+I ,7); write(Temp); delay(30);
GotoXY(23,7); ClrEol;
End;
For I:=1 to 14-top do
Begin
Delay(30);
GotoXY(41,6+I); write(' ');
GotoXY(41,7+I); write(Temp);
End;
End;

Procedure PopAnim (Temp:char);


Begin
For I := 1 to 14-top do
Begin
Delay(30);
GotoXY(41,22-I-Top); write(' ');
GotoXY(41,21-I-Top); write(Temp);
End;
For I:=1 to 19 do
Begin
GotoXY(40+I ,7); write(Temp); delay(30);
GotoXY(16,7); ClrEol;
End;
End;

Procedure Push(e:char);
Begin
Inc(Top);
Stack[Top] :=e;
PushAnim;
End;

Procedure Pop(e:char);
Begin
If Top <> 0 then
Begin
E:=stack[Top]; popAnim(e);
Dec(Top);
End else
Begin
GotoXY(1,7); write('Stack Telah Kosong');readkey;
GotoXY(1,7);ClrEol
End;
End;
Begin
ClrScr;
Writeln('ANIMASI STACK');
Writeln('1. PUSH');
Writeln('2. POP');
Writeln('3. QUIT');
Writeln('Pilihan anda [1/2/3] = ');
GotoXY(59,6);Write('\');
GotoXY(59,8);Write('/');
GotoXY(37,10);Write('\ /');
For I:=1 to 11 do
Begin
GotoXY (38,10+I);
If I = 11 then write('|_______|') else write ('|
|');
End;
Top := 0;
Repeat
GotoXY(19,5);ClrEol;
Pil :=readkey; Write(pil);
If Pil ='1' then
Begin
If Top<> max then
Begin
GotoXY(1,7); write('Masukkan satu huruf=');
Temp:=readkey;write(Temp);
Push(Temp);
GotoXY(1,7);ClrEol;
End else
Begin
GotoXY(1,7); write('Stack sdh penuh');readkey;
GotoXY(1,7);ClrEol;
End;
End else
If pil ='2' then Pop(Temp);
Until pil ='3';
End.

Anda mungkin juga menyukai