Jumat, 07 Agustus 2009

Antrian dengan Pascal

program antrian;

uses
WinCrt; { Allows Writeln, Readln, cursor movement, etc. }

type
PQueueType = ^QueueType;
QueueType = record
Data: Integer;
Next: PQueueType;
end;
var
Queue: PQueueType;
Input: string;
data, code, i: integer;
procedure Antri(var q: PQueueType; d: Integer);
var
r: PQueueType;
begin
if (q = nil) then
begin
new(r);
r^.Data := d;
r^.Next := nil;
q := r;
end
else
Antri(q^.Next, d);
end;

function ProsesAntrian(var q: PQueueType):integer;
var
r: PQueueType;
begin
prosesAntrian := 0;
if (q <> nil) then
begin
r := q;
q := q^.Next;
prosesAntrian := r^.Data;
Dispose(r);
end;
end;

procedure TampilAntrian(q: PQueueType);
begin
if (q <> nil) then
begin
write(q^.Data:5);
TampilAntrian(q^.Next);
end;
end;

begin
writeln('Program Antrian');
writeln('===============');
writeln;
Queue := nil;
repeat
write('Masukkan angka: ');
Readln(Input);
if (input <> '') then
begin
Val(input, data, code);
if (code <> 0) then
data:= 0;
Antri(Queue, data);
end;
until (input = '');
writeln;
writeln('Di dalam antrian: ');
TampilAntrian(Queue);
writeln;
writeln;
writeln('Memproses Antrian: ');
i := 1;
while (Queue <> nil) do
begin
writeln('Antrian ke-', i, ': ', prosesAntrian(Queue));
Inc(i);
end;

end.

2 komentar:

FORUM IT mengatakan...

Terima kasih atas programnya

FORUM IT mengatakan...

Luaar biasa

Poskan Komentar