uses crt;
type
Pnode = ^node;
node = record
info:char;
before,next:Pnode;
end;
double = object
awal,baru,akhir:Pnode;
procedure initial;
procedure tambah_awal(p:char);
procedure tambah_akhir(p:char);
procedure cetak;
End;
procedure double.initial;
begin
awal:=nil;
akhir:=nil;
end;
procedure double.tambah_awal(p:char);
begin
new(baru);
baru^.info:=p;
baru^.before:=nil;
if awal=nil then
begin
awal:=baru;
akhir:=baru;
end
else
begin
baru^.next:=awal;
awal^.before:=baru;
awal:=baru;
end;
end;
procedure double.tambah_akhir(p:char);
begin
new(baru);
baru^.info:=p;
baru^.next:=nil;
if awal=nil then
begin
awal:=baru;
akhir:=baru;
end
else
begin
baru^.before:=akhir;
akhir^.next:=baru;
akhir:=baru;
end;
end;
procedure double.cetak;
var
bantu:pnode;
c:char;
begin
bantu:=awal;
repeat
if (bantu =awal) then
textcolor(lightgreen);
if (bantu =akhir) then
textcolor(lightred);
write(bantu^.info,'-');
repeat
c:=readkey;
until ord(c) in[75,77,27];
case ord(c) of
75: if bantu <>awal then bantu:=bantu^.before;
77: if bantu <> akhir then bantu:=bantu^.next;
end;
textcolor(white);
until c=#27;
end;
var
list:double;
k:char;
begin
clrscr;
textcolor(white);
writeln(' -Program Double Linked List-');
repeat
write('Karakter : ');
k:=readkey;
if not(k in [#13,#27]) then
list.tambah_akhir(upcase(k));
writeln(k);
until k=#27;writeln;
list.cetak;
end.
0 komentar:
Posting Komentar