Logika Algoritma : Program Antrian Melingkar

Buat temen-temen di 12.01.C/851
Ini melengkapi saja jadi hanya contoh programnya karena untuk pseducode dan flowchart kan sudah…

Antrian Melingkar


uses wincrt;

type lingkar=array[1..10] of char;

type ling=record

nilai:lingkar;

dep:integer;

bel:integer;

isi:integer;

end;

var n:integer;

antrian:ling;

{———————————————————————}

procedure push(var antrian:ling;x:char);

begin

if antrian.isi=n then write(‘antrian penuh’)

else

begin

if antrian.bel=n then antrian.bel:=1

else antrian.bel:=antrian.bel+1;

antrian.nilai[antrian.bel]:=x;

antrian.isi:=antrian.isi+1;

end;

end;

{———————————————————————}

procedure pop(var antrian:ling;var x:char);

begin

if antrian.isi=0 then write(‘antrian kosong’)

else

begin

antrian.dep:=antrian.dep+1;

if antrian.dep=n+1 then antrian.dep:=1;

x:=antrian.nilai[antrian.dep];

antrian.nilai[antrian.dep]:=’ ‘;

antrian.isi:=antrian.isi-1;

end;

end;

{———————————————————————}

var i,ingin:integer;

x:char;

begin

n:=5;

i:=0;

repeat

i:=i+1;

write(‘antrian ke – ‘,i,’ = ‘);readln(x);

push(antrian,x);

until i=n;

for i:=1 to antrian.bel do write(antrian.nilai[i],’ ‘);

readln;

repeat

write(‘Anda ingin 0. Udah, 1. Push, 2. pop’);readln(ingin);

if ingin<>0 then

case ingin of

1: begin

write(‘nilai yang akan masuk : ‘);readln(x);

push(antrian,x);

for i:=1 to n do

write(antrian.nilai[i],’ ‘);

writeln;

end;

2: begin

x:=’ ‘;

pop(antrian,x);

writeln(‘Data keluar = ‘,x);

for i:=1 to n do

write(antrian.nilai[i],’ ‘);

8

writeln;

end;

end

until ingin=0;

end.

Selamat berlibur panjang

One response to “Logika Algoritma : Program Antrian Melingkar

  1. Thank for information….

    @sama-sama

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s