Uses Wincrt;
Const Max_Antrian = 5;
Type Antri = Array [1..Max_Antrian] of Char;
Var Antrian : Antri;
Depan, Belakang : Integer;
Elemen,Pil,Pil1 : Char;
Procedure InitAntrian;
Begin
Depan:=0;
Belakang:=0;
End;
Procedure Tambah(Var Antrian: Antri; X: Char);
Begin
If Belakang<>Max_Antrian Then
Begin
Inc(Belakang);
Antrian[Belakang]:=X;
End
Else
Writeln('ANTRIAN SUDAH PENUH');
End;
Procedure Hapus(Var Antrian: Antri);
Var i: Integer;
Begin
If Depan<>Belakang Then
Begin
For i:= 2 To Belakang Do
Begin
Antrian[i-1]:=Antrian[i];
End;
Antrian[Belakang]:=' ';
Dec(Belakang);
End
Else
Writeln('ANTRIAN KOSONG');
End;
Procedure Tampilkan;
Var i : Integer;
Begin
Write('Keluar <== |');
For i := 1 To Max_Antrian Do
Write(' ',Antrian[i],' |');
Write(' <== Masuk');
End;
Begin
InitAntrian;
Repeat
Clrscr;
Writeln('DAFTAR MENU PILIHAN');
Writeln('===================');
Writeln('1. Tambah Elemen');
Writeln('2. Hapus Elemen');
Writeln('3. Exit');
Write('Pilihan [1..3]: ');Pil:=ReadKey;
Case Pil of
'1' : Begin
Repeat
Clrscr;
Writeln('TAMBAH ELEMEN');
Writeln('=============');
Writeln;
Write('Isikan Elemen: ');Readln(Elemen);
Tambah(Antrian,Elemen);
Writeln;Writeln;
Tampilkan;
Writeln;Writeln;
Write('Mau Tambah Elemen Lagi? [Y/T]: ');Pil1:=Upcase(ReadKey);
Until Pil1<>'Y';
End;
'2' : Begin
Repeat
Clrscr;
Writeln('HAPUS ELEMEN');
Writeln('=============');
Hapus(Antrian);
Writeln;Writeln;
Tampilkan;
Writeln;Writeln;
Write('Mau Hapus Elemen Lagi? [Y/T]: ');Pil1:=Upcase(ReadKey);
Until Pil1<>'Y';
End;
End;
Until Pil='3';
End.
0 komentar:
Posting Komentar