link list
program LINK_LIST;
uses wincrt;
type addres=^buku;
buku=record
nama:string[25];
alamat:string[100];
next:addres;
end;
var
head,tail,now:addres;
x:char;
procedure buat;
begin
head:=nil;tail:=nil;
end;
procedure first;
begin
now:=head
end;
procedure setelah;
begin
if now^.next<>nil then
now:=now^.next;
end;
procedure ubah(var a,b:string);
begin
now^.nama:=a;
now^.alamat:=b;
end;
{procedure hapus;
var x:addres;
begin
writeln('masukkan nama yang akan dihapus');readln(now^.nama);
if now^.nama<>head^.nama then
begin
x:=head;
while x^.next<>now do
x:=x^.next;
x^.next:=now^.next;
end;
if now^.nama=head^.nama then
head:=head^.next;
dispose(now);
now:=head;
end;}
procedure tambah;
var baru:addres;
begin
new(baru);
write('Masukkan Nama : ');readln(baru^.nama);
write('Masukkan NRP : ');readln(baru^.alamat);
if head=nil then
head:=baru
else
tail^.next:=baru;
tail:=baru;
tail^.next:=nil;
end;
procedure tampil;
var bantu:addres;
begin
clrscr;
bantu:=head;
writeln('.: DATA MAHASISWA :.');
writeln(' ____ _________ ');
writeln;
repeat
writeln('Nama:',bantu^.nama);
writeln('NRP:',bantu^.alamat);
writeln;
bantu:=bantu^.next;
until bantu=nil;
end;
procedure bersih ;
begin
while head<>nil do
begin
now:=head;
head:=head^.next;
dispose(now);
end;
end;
begin
repeat
clrscr;
writeln('1.Mengisi Buku ');
writeln('2.Melihat Isi Buku');
writeln('3.Membersihkan Daftar buku ');
write('Masukkan Pilihan Anda (keluar alt + F4) : ');readln(x);
writeln;
case x of
'1':
begin
tambah;
end;
'2':begin
tampil;
readln;
end;
{'3':
begin
tambah;
end;}
'3':
begin
bersih;
end;
{'5':begin
first;setelah;hapus;
end;}
end;
until x=#27;
end.
Komentar