uses crt;
type
PPNode = ^PNode;
PNode = ^TNode;
TNode = record
data : integer;
next : PNode;
end;
procedure tambah(d,b : PPNode ; nilai : integer);
var
temp : PNode;
begin
new(temp);
temp^.data := nilai;
temp^.next := nil;
if (d^ = nil) then
begin
d^ := temp;
end
else
begin
b^^.next := temp;
end;
b^ := temp;
end;
procedure hapus(d,b : PPNode);
var
temp : PNode;
begin
if (d^ = nil) then
begin
writeln('Tidak terdapat record dalam queue');
end
else
begin
temp := d^;
d^ := temp^.next;
dispose(temp);
if (d^ = nil) then
begin
b^ := nil;
end;
end;
end;
procedure tampilkan(q : PNode);
var
nilai : integer;
begin
while(q<> nil) do
begin
nilai := q^.data;
writeln(nilai);
q := q^.next;
end;
end;
var
depan, belakang : PNode;
begin
clrscr;
depan := nil;
belakang := nil;
tambah(@depan, @belakang, 100);
tambah(@depan, @belakang, 200);
tambah(@depan, @belakang, 300);
tambah(@depan, @belakang, 400);
writeln('Nilai dalam queue');
tampilkan(depan);
hapus(@depan, @belakang);
writeln;
writeln('Setelah record terdepan Dihapus : ');
tampilkan(depan);
readln;
end.
0 komentar:
Posting Komentar