program linked_list;
uses crt;
type ptrdata = ^recorddata;
recorddata = record
item : string;
berikut : ptrdata
end;
var pd : ptrdata;
elem : string;
procedure node_baru(var baru: ptrdata; elemen: string);
var ps: ptrdata;
begin
new(ps);
new(baru);
baru^.item := elemen;
baru^.berikut := nil;
end;
Procedure tambah_depan(Var depan : ptrData; elemen : string);
Var ps :ptrdata;
Begin
new(ps);
new(depan);
node_baru(ps,elemen);
ps^.berikut := pd;
pd:=ps ;
End;
begin
clrscr;
new(pd);
elem := 'Nama : Katon Galih Wicaksono';
tambah_depan(pd, elem);
writeln(pd^.item);
elem := 'NIM : J1F114028';
tambah_depan(pd, elem);
writeln(pd^.item);
writeln;
elem := 'Nama : Ketut Mega Fortuna';
tambah_depan(pd, elem);
writeln(pd^.item);
elem := 'NIM : J1F114029';
tambah_depan(pd, elem);
writeln(pd^.item);
readln;
end.
Berikut Outputnya :
Pointer
Senin, 13 April 2015
uses crt;
var
judul,pengarang, tglpj, tglkem:^string;
begin
clrscr;
new(judul);
Judul^:='Judul Buku : Perahu kertas';
new(Pengarang);
Pengarang^:='Pengarang Buku : Dewi Lestari';
tglpj:='Tanggal pinjam: 10';
tglkem:='Tanggal kembali 20';
writeln(Judul^);
writeln(Pengarang^);
writeln(tglpj);
writeln(tglkem);
Judul := pengarang; writeln(Judul^);
Judul^:='Judul Buku : Perahu Kertas';
writeln(Judul^);
Pengarang^:='Pengarang Buku : Dewi Lestari';
writeln(Pengarang^);
readln;
end.
Berikut Hasil Outputnya :
var
judul,pengarang, tglpj, tglkem:^string;
begin
clrscr;
new(judul);
Judul^:='Judul Buku : Perahu kertas';
new(Pengarang);
Pengarang^:='Pengarang Buku : Dewi Lestari';
tglpj:='Tanggal pinjam: 10';
tglkem:='Tanggal kembali 20';
writeln(Judul^);
writeln(Pengarang^);
writeln(tglpj);
writeln(tglkem);
Judul := pengarang; writeln(Judul^);
Judul^:='Judul Buku : Perahu Kertas';
writeln(Judul^);
Pengarang^:='Pengarang Buku : Dewi Lestari';
writeln(Pengarang^);
readln;
end.
Berikut Hasil Outputnya :
Program gabungan Sorting dan Searching
Minggu, 05 April 2015
uses crt;
const
nmin = 1;
nmax = 100;
type
penunjukbrg = ^catatanbrg;
catatanbrg = record
kode :integer;
nama : string[25];
harga :real;
end;
var
databrg : array [nmin..nmax] of penunjukbrg;
i, j : byte;
temp : catatanbrg;
a: integer;
indeks : integer;
function seqsearch1(xx : integer): integer;
begin
clrscr;
write('masukkan data barang:'); readln(a);
for i := 1 to a do
begin
writeln;
writeln('Barang ke ', i:2, ' :');
new(databrg[i]);
with databrg[i]^ do
begin
write('Kode Barang : ');readln(kode);
write('Nama Barang : ');readln(nama);
write('Harga Barang : Rp.');readln(harga);
end;
end;
writeln('Data Barang Belanjaan :');
writeln('-----------------------');
writeln;
writeln('Kode Barang Nama Barang Harga Barang ');
writeln;
for i := 1 to a do
with databrg[i]^ do
writeln(kode:5, Nama:15, Harga:20:2);
writeln; writeln;
writeln('Data Berdasarkan Abjad Barang :');
writeln;
writeln('Kode barang Nama Barang Harga Barang ');
begin
for i := 1 to a do
for j := 1 to a do
with databrg[i]^ do
if databrg[i]^.nama < databrg[j]^.nama then
Begin
temp := databrg[i]^;
databrg[i]^ := databrg[j]^;
databrg[j]^ := temp;
end;
for i := 1 to a do
with databrg[i]^ do
writeln(kode:5, Nama:15, Harga:20:2);
writeln;
end;
end;
begin
with databrg[i]^ do
begin
clrscr;
write('Nilai yang dicari = '); readln(kode);
writeln;
indeks:=seqsearch1(kode);
if indeks <> 0 then
write(kode,' ditemukan pada indeks ke-',indeks)
else
write(kode,' tidak ditemukan');
writeln;
writeln;
end;
readkey;
end.
const
nmin = 1;
nmax = 100;
type
penunjukbrg = ^catatanbrg;
catatanbrg = record
kode :integer;
nama : string[25];
harga :real;
end;
var
databrg : array [nmin..nmax] of penunjukbrg;
i, j : byte;
temp : catatanbrg;
a: integer;
indeks : integer;
function seqsearch1(xx : integer): integer;
begin
clrscr;
write('masukkan data barang:'); readln(a);
for i := 1 to a do
begin
writeln;
writeln('Barang ke ', i:2, ' :');
new(databrg[i]);
with databrg[i]^ do
begin
write('Kode Barang : ');readln(kode);
write('Nama Barang : ');readln(nama);
write('Harga Barang : Rp.');readln(harga);
end;
end;
writeln('Data Barang Belanjaan :');
writeln('-----------------------');
writeln;
writeln('Kode Barang Nama Barang Harga Barang ');
writeln;
for i := 1 to a do
with databrg[i]^ do
writeln(kode:5, Nama:15, Harga:20:2);
writeln; writeln;
writeln('Data Berdasarkan Abjad Barang :');
writeln;
writeln('Kode barang Nama Barang Harga Barang ');
begin
for i := 1 to a do
for j := 1 to a do
with databrg[i]^ do
if databrg[i]^.nama < databrg[j]^.nama then
Begin
temp := databrg[i]^;
databrg[i]^ := databrg[j]^;
databrg[j]^ := temp;
end;
for i := 1 to a do
with databrg[i]^ do
writeln(kode:5, Nama:15, Harga:20:2);
writeln;
end;
end;
begin
with databrg[i]^ do
begin
clrscr;
write('Nilai yang dicari = '); readln(kode);
writeln;
indeks:=seqsearch1(kode);
if indeks <> 0 then
write(kode,' ditemukan pada indeks ke-',indeks)
else
write(kode,' tidak ditemukan');
writeln;
writeln;
end;
readkey;
end.
Berikut Output akhirnya :
Langganan:
Postingan (Atom)