STACK / TUMPUKAN PADA PASCAL


uses crt;
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(24+i,7);write(temp);delay(30);
              gotoxy(24,7);clreol;
         end;
     for i := 1 to 14-top do
         begin
              delay(8000);
              gotoxy(42,6+i);write(' ');
              gotoxy(42,7+i);write(temp);
         end;
     end;

procedure popAnim(temp : char);
begin
     for i := 1 to 14-top do
         begin
              delay(30);
              gotoxy(42,22-i-top);write(' ');
              gotoxy(42,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 sudah kosong ');readkey;
          gotoxy(1,7);clreol;
         end;
     end;

begin
clrscr;
       writeln ('animasi stack ');
       writeln ('1. push ');
       writeln ('2. pop ');
       writeln ('3. exit ');
       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 satu huruf = ');
                      temp := readkey; write(temp);
                      push(temp);
                      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(temp);
       until pil = '3'
end.

0 komentar:

Posting Komentar

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
This Theme Modified by Kapten Andre based on Structure Theme from MIT-style License by Jason J. Jaeger