uses crt;
const max = 10;
type antri = array [1..max] of char;
var antrian : antri;
L,R: integer;
elemen, pilih : char;
function nihil(Q:antri):Boolean;
begin
nihil:=(L=R);
end;
function daerah_parkir_kanan_penuh(q:antri):boolean;
begin
daerah_parkir_kanan_penuh:=(R=(max-1));
end;
function daerah_parkir_kiri_penuh(q:antri):boolean;
begin
daerah_parkir_kiri_penuh:=(L=0);
end;
procedure masukkan_di_kanan(var antrian: antri; x:char);
begin
R:=R+1;
if not(nihil(antrian)) then
begin
antrian[R]:=x;
write(x);
end;
end;
procedure masukkan_di_kiri(var antrian: antri; x:char);
begin
L:=L-1;
if not(nihil(antrian)) then
begin
antrian[L]:=x;
write(x);
end;
end;
procedure keluarkan_mobil_kanan (var antrian: antri);
begin
if (L<R+1) then
begin
elemen:=antrian[R];
R:=R-1;
end
else writeln('Antrian nihil');
end;
procedure keluarkan_mobil_kiri (var antrian: antri);
begin
if (L<R+1) then
begin
elemen:=antrian[L];
L:=L+1;
end
else writeln('Antrian nihil');
end;
procedure cetak;
var
i:byte;
begin
for i:= L to R do
write(antrian[i]);
end;
begin
clrscr;
L:=5;
R:=5;
repeat
clrscr;
writeln('[a]. Masuk Mobil Di Kanan');
writeln('[b]. Masuk Mobil Di Kiri');
writeln('[c]. keluarkan mobil di kanan');
writeln('[d]. keluarkan mobil di kiri');
writeln('[e]. Cetak Data Parkir');
writeln('[f]. Selesai');
write('pilihan: '); readln(pilih);
case pilih of
'a' : begin
writeln('Masuk Mobil Di Kanan (maksimal 5) ');
write('isikan elemennya: ');
readln(elemen);
masukkan_di_kanan(antrian,elemen);
end;
'b' : begin
writeln('Masuk Mobil Di Kiri (maksumal 5) ');
write('isikan elemennya: ');
readln(elemen);
masukkan_di_kiri(antrian,elemen);
end;
'c' : begin
keluarkan_mobil_kanan(antrian);
end;
'd' : begin
keluarkan_mobil_kiri(antrian);
end;
'e' : begin
writeln('Data yang sudah anda masukkan: ');
cetak;
readln;
end;
end;
until pilih = 'f';
end.
end.
Tidak ada komentar:
Posting Komentar