Membuat Tumpukan Kata Dengan Push dan Pop
Langsung saja copy codingnya:
program arraystack;
uses crt;
const Topmax = 6;
var
top, i : byte;
pil : char;
temp, e : string;
stack : array[1..Topmax] of string;
procedure pushAnim;
begin
for i:= 1 to 18 do
begin
gotoxy(23+i, 7); write(temp); delay(50);
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:string);
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(50);
gotoxy(16, 7); clreol;
gotoxy(59, 7); writeln(temp);
end;
end;
procedure push(e : string);
begin
inc(top);
stack[top] := e;
pushanim;
end;
procedure pop(e : string);
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('Pilihan : ');
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 <> Topmax then
begin
gotoxy(1, 7); write('Masukkan Kata = ');
temp:=readkey; readln(temp);
i:= length(temp);
if i > 6 then
begin
gotoxy(1, 9); writeln('Karakter Huruf Penuh'); readkey;
end
else
push(temp);
gotoxy(1, 9); clreol;
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 ='3';
end.
uses crt;
const Topmax = 6;
var
top, i : byte;
pil : char;
temp, e : string;
stack : array[1..Topmax] of string;
procedure pushAnim;
begin
for i:= 1 to 18 do
begin
gotoxy(23+i, 7); write(temp); delay(50);
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:string);
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(50);
gotoxy(16, 7); clreol;
gotoxy(59, 7); writeln(temp);
end;
end;
procedure push(e : string);
begin
inc(top);
stack[top] := e;
pushanim;
end;
procedure pop(e : string);
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('Pilihan : ');
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 <> Topmax then
begin
gotoxy(1, 7); write('Masukkan Kata = ');
temp:=readkey; readln(temp);
i:= length(temp);
if i > 6 then
begin
gotoxy(1, 9); writeln('Karakter Huruf Penuh'); readkey;
end
else
push(temp);
gotoxy(1, 9); clreol;
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 ='3';
end.
0 komentar: