Berikut ini adalah contoh program pascal animasi stack (tumpukan) .
Program AnimasiStack;
Uses wincrt;
const
max = 10;
var
top,i : byte;
pil,tem,E : char;
stack : array [1..max] of char;
procedure pushanim;
begin
for i :=1 to 18 do
begin
gotoxy(23+i,7); write(tem);
{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(tem);
end;
end;
procedure popanim(tem:char);
begin
for i:=1 to 14-top do
begin
{delay(30);}
gotoxy(41,22-i-top); write(' ');
gotoxy(41,21-i-top); write(tem);
end;
for i:=1 to 19 do
begin
gotoxy(40+i,7); write(tem);
{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(49,6);write('\');
gotoxy(49,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(23,5);clreol;
pil := readkey;write(pil);
if pil ='1' then
begin
if top<> max then
begin
gotoxy(1,7);write('Masukkan satu Huruf = ');
tem := readkey;write(tem);
push(tem);
gotoxy(1,7);clreol;
end else
begin
gotoxy(1,7);write('Stack sudah penuh');readkey;
gotoxy(1,7);clreol;
end;
end else
if pil='2' then pop(tem);
until pil='3';
end.
Tags : Struktur Data, Animasi Stack , Stack, Tumpukan, pascal, program pascal, pascal stack
keren mas bero
BalasHapuskeren sumpah (y)
BalasHapus