Tips for heathy life

Tips for heathy life

Minggu, 02 November 2008

STACK in Pascal

Program ArrayStack;

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(temp);{delay(30); }
gotoxy(41,21-i-top);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 [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 suatu huruf = ');
temp:=readkey;write(temp);
Push(temp);
gotoxy(1,7);CLrEol;
end else
begin
gotoxy(1,7);write(' Stack telah penuh' );
readkey;
gotoxy(1,7);ClrEol;
end;
end else
if Pil='2' then Pop(temp);
until Pil='13';
end.

0 komentar:

Posting Komentar