Wah, untuk mahasiswa Teknik Informatika yang susah dalam membuat program antrian, kali ini saya akan postingkan.
program animation_queue;
uses wincrt;
const max_elemen =10;
type antri = array [1..max_elemen] of char;
var
antrian : antri;
q : antri;
d : char;
isi : antri;
depan, belakang, pilih : integer;
elemen : char;
procedure kotak;
var
i: integer;
begin
gotoxy(20,15);
for i:= 1 to max_elemen * 4 + 1 do
write('-');
gotoxy(20,16);
for i:= 1 to max_elemen do
write('| ');
writeln('|');
gotoxy(20,17);
for i:= 1 to max_elemen * 4 +1 do
write('-');
gotoxy(8,16);writeln('<---- Out');
gotoxy(22+max_elemen*4+1,16);
writeln('<---- In');
end;
procedure letakkan(x: char; r:integer);
begin
gotoxy(18+4*r,16);
write(x);
end;
function kosong(q: antri): boolean;
begin
kosong:=(depan=belakang)
end;
procedure tambah(var antrian: antri;x:char);
begin
if belakang=max_elemen then belakang:=1
else belakang:=belakang+1;
if not (kosong(antrian)) then
begin
antrian[belakang]:=x;
letakkan(x,belakang);
end
else
begin
gotoxy(40,9);
write('OVERFLOW');
repeat
{menunggu sampai ada tombol ditekan}
until keypressed;
gotoxy(40,9);
write(' ':30);
belakang:=belakang-1;
if belakang=0 then
belakang:=max_elemen
end
end;
function qkosong(q:antri):boolean;
begin
qkosong:= (depan = belakang);
end;
procedure Dequeue(var q:antri; ed:char);
begin
if not(qkosong(q)) then
begin
if depan = max_elemen then depan :=1
else depan := depan+1;
ed := isi[depan];
end;
end;
procedure tampil(q: antri);
var i,awal : integer;
begin
CLRSCR;
writeln('Queue to Data');
if depan = max_elemen then awal :=1
else awal := depan +1;
for i:=awal to belakang do
writeln(i:3,' ':5,isi[i],' ');
READLN;
end;
function hapus(var antrian: antri):char;
begin
if depan=max_elemen then
depan:=1
else
begin
depan:=depan+1;
hapus:=antrian[depan]
end
end;
{program utama}
begin
clrscr;
kotak;
depan:=0;
belakang:=0;
repeat
for pilih:=5 to 9 do
begin
gotoxy(40,pilih);write(' ':39);
end;
gotoxy(1,1);
writeln(' MENU ');
writeln('===================');
writeln;
writeln(' 1. Add a New Element (Enqueue)');
writeln(' 2. Vanish An Element (Dequeue) ');
writeln(' 3. FINISH and EXIT');
writeln;writeln;
writeln(' YOURS CHOICE:');
writeln;
write ('-------THANK YOU FOR USING THIS PROGRAM---------');
writeln;
write (' THE PROGRAM CREATED BY ');
writeln;
write (' RAHMAD KURNIAWAN ');
writeln;
write (' http://rahmad.co.nr ');
writeln;
repeat
gotoxy(22,9);writeln(' ');
gotoxy(22,9);readln(pilih);
until (pilih>=1) and(pilih<=3);
case pilih of
1 : begin
gotoxy(40,4);
writeln ('--------------');
gotoxy(40,5);
writeln('ADD AN ELEMENT');
gotoxy(40,6);
writeln('---------------');
gotoxy(40,8);
write('ENTER AN ELEMENT:');
readln(elemen);
tambah(antrian,elemen);
end;
2 : begin
if not(kosong(antrian)) then
begin
Dequeue(q,d);
tampil(q);
end
else
begin
gotoxy (30,9);
writeln ('UNDER FLOW');
elemen:=readkey;
gotoxy (30,9);write (' ':30);
end
end
end;
until pilih=3
end.
Artikel keren lainnya:
1 Tanggapan untuk "PROGRAM ANTRIAN DALAM PASCAL"
MAS BROW,, KALAU MAU NAMBAH NPM MA KODE KELASNYA, PALING ATAS SAAT DI JALAN KAN, GIMANA CARANYA MAS BROW?
Post a Comment