Implementasi List dengan Array

program STR_DATA;

uses wincrt;

const Max_Elemen = 10;

type LIST = array[1..Max_Elemen] of char;

var DLIST : LIST;
Depan,
Belakang,
Pilih : integer;
Elemen : char;

{*******************************************
* Prosedur untuk menggambar kotak list *
******************************************* }
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); write(‘<– ‘);
gotoxy(22+Max_Elemen*4+1,16);
writeln(‘<– ‘);
end; {* prosedur KOTAK *}

{*************************************
* Prosedur untuk meletakkan elemen *
* dalam kotak LIST *
*************************************}
procedure LETAKKAN(X : char; R : integer);

begin
gotoxy(18+4*R,16);
write(X)
end; {* prosedur LETAKKAN *}

{***************************************
* Fungsi untuk mencek keadaan antrian *
*************************************** }
function KOSONG(Q : LIST) : boolean;

begin
Kosong := (Depan = Belakang)
end;

{**************************************************
* Prosedur untuk menambah elemen baru selama *
* antrian belum penuh. Jika antrian sudah penuh, *
* program akan menampilkan suatu pesan. *
**************************************************}
procedure TAMBAH(var DLIST : LIST; X : char);

begin
{* Menambahkan elemen baru *}
if Belakang = Max_Elemen then Belakang := 1
else Belakang := Belakang + 1;

if not(KOSONG(DLIST)) then
begin
DLIST[Belakang] := X;
LETAKKAN(X,Belakang)
end
else
{* Antrian penuh *}
begin
gotoxy(40,9);
write(‘MAAF BOS LIST SUDAH PENUH’);

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; { *** prosedur TAMBAH *** }

{*************************************************
* Prosedur untuk menghapus elemen dari LIST *
* yang belum kosong. Jika LIST kosong, *
* program akan menampilkan suatu pesan *
*************************************************}
function HAPUS(var DLIST : LIST) : char;

begin
if Depan = Max_Elemen then
Depan := 1
else
begin
Depan := Depan + 1;
HAPUS := DLIST[Depan]
end
end; {* fungsi HAPUS *}

{*****************
* Program utama *
*****************}

begin { *** program utama *** }
clrscr;
KOTAK;
Depan := 0; Belakang := 0;
repeat
for Pilih := 5 to 9 do
begin
gotoxy(40,Pilih); write(‘ ‘:39)
end;
gotoxy(1,1);
writeln(‘ LOGO……………………’);
writeln(‘——————————-‘);
writeln;
writeln(‘ TUGAS PRAKTEK STRUKTUR DATA’);
writeln(‘ NAMA : ************’);
writeln(‘ NPM : *************’);
writeln;
writeln(‘—————————— ‘);
write(‘PILIH 1 MENAMBAH, 2 HAPUS & 3 KELUAR :’);
repeat
write(‘ ‘);
readln(Pilih)
until (Pilih >= 1) and (Pilih <= 3);
case Pilih of
{* Memilih aktifitas *}
1 : begin

{* Menambah elemen ke dalam LIST *}
writeln(‘ ‘);
writeln;
write(‘Data list : ‘);
readln(Elemen);
TAMBAH(DLIST,Elemen);
end;

2 : begin
{* Menghapus elemen dari LIST *}
if not (KOSONG(DLIST)) then
begin
Elemen := HAPUS(DLIST);
LETAKKAN(‘ ‘,Depan)
end
else
begin
gotoxy(30,9);
writeln(‘ANTRIAN KOSONG …’);
Elemen := readkey;
gotoxy(30,9); write(‘ ‘:30)
end
end
end;
until Pilih = 3

end.

One Response to Implementasi List dengan Array

  1. 4FB (Air Force Base) says:

    Matur Suwun kang… mau tak downlood dulu lumayan juga dari pada saya mikir ga bisa-bisa, ampe pusing bs-bs kepala botak,…… ga lucu khan nti tmen2 FTi/II ngetawain.Ha ha..hA… thank’s lot of

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

WordPress.com

WordPress.com is the best place for your personal blog or business site.

%d bloggers like this: