uses crt;

var
stack:array[1..10] of integer;
i,pos,pil:integer;

procedure push;
var
bil:integer;
begin
clrscr;
if (pos>=10) then
begin
writeln(‘Stack sudah penuh’); readln();
end
else
begin
write(‘Masukkan bilangan : ‘);readln(bil);
pos:=pos+1;
stack[pos]:=bil;
end;
end;

procedure pop;
begin
clrscr;
if (pos=0) then
begin
writeln(‘Stack masih kosong’);readln();
end
else
begin
stack[pos]:=-1;
pos:=pos-1;
end;
end;

procedure empty;
var
i:integer;
begin
clrscr;
if (pos=0) then
begin
writeln(‘Stack masih kosong’);readln();
end
else
begin
for i:=1 to pos do
begin
stack[i]:=-1;
end;
pos:=0;
end;
end;

procedure display;
var
i,j:integer;
begin
clrscr;
if (pos=0) then
begin
writeln(‘Stack masih kosong’);readln();
end
else
begin
j:=1;
for i:=pos downto 1 do
begin
gotoxy(1,i);
write(stack[j]);
j:=j+1;
end;
readln();
end;
end;

begin
clrscr;
{inisialisasi stack}
for i:=1 to 10 do
begin
stack[i]:=-1;
end;
{posisi awal stack}
pos:=0;
{pilihan menu stack}
while (pil<>5) do
begin
clrscr;
writeln(‘MENU PILIHAN STACK ‘);
writeln(‘================== ‘);
writeln(‘1. Isi Stack (PUSH)’);
writeln(‘2. Ambil (POP) ‘);
writeln(‘3. Kosongkan Stack ‘);
writeln(‘4. Lihat Stack ‘);
writeln(‘5. Selesai ‘);
write(‘Pilihan Anda :’); readln(pil);
case pil of
1: push();
2: pop();
3: empty();
4: display();
end;
end;
end.