Contoh program pascal linked list
Source code :
Uses crt;
Type pointer = ^typedata;
Typedata = record
Nilai : Integer;
Berikutnya : pointer;
End;
Var list :pointer;
Procedure mas_dep(var L :
pointer; x : Integer);
Var baru : pointer;
Begin
New(baru);
Baru^.Nilai:=x;
Baru^.Berikutnya:= nil;
If L= nil then L:=baru
Else
Begin
Baru^.berikutnya :=L;
L:= baru;
End;
End;
Procedure cetak (L:pointer);
Var bantu : pointer;
Begin
Bantu:= L;
While bantu <> nil do
Begin
Write (bantu^.Nilai:3);
Bantu:=bantu^.Berikutnya;
End;
End;
Var bil, bil2 : integer;
Jwb : char;
Begin
Clrscr;
New(list);
List:=nil;
Writeln ('Program linked List');
Writeln;
Writeln (' Masuk depan');
Repeat
Begin
Writeln;
Write ('Masukkan bilangan : ');
readln(bil);
mas_dep(list,bil);
Write ('Lagi [Y/T] : ');
readln(jwb);
End;
Until jwb='T';
Write('Hasil : ');
Cetak(list);
Writeln;
Readln;
End.
|
Output program :
1. Input bilangan pertama.
2. Input bilangan kedua.
3. Input bilangan ketiga.
4. Output Hasil.
1 komentar so far
bisa bertanya ?
EmoticonEmoticon