USES CRT;

TYPE
DataString  = STRING[30];
ListPointer = ^ListRecord;
ListRecord  = RECORD
Data : DataString;
Next : ListPointer;
END;
VAR
Awal : ListPointer;
Akhir : ListPointer;
Baru : ListPointer;
Bantu : ListPointer;
Pilihan : Integer;

PROCEDURE InsertBelakang;
VAR
Teks:STRING[30];
BEGIN
WRITELN(‘Masukkan datanya :’); READLN(Teks);
IF (Awal=Nil) THEN
BEGIN
New(Baru);
Awal:=Baru;
Akhir:=Baru;
Awal^.Data:=Teks;
Awal^.Next:=Nil;
Akhir^.Next:=Nil;
END
ELSE
BEGIN
New(Baru);
Baru^.Data:=Teks;
Akhir^.Next:=Baru;
Baru^.Next:=Nil;
Akhir:=Baru;
END;
END;

PROCEDURE InsertDepan;
VAR
Teks:STRING[30];
BEGIN
WRITELN(‘Masukkan datanya :’); READLN(Teks);
IF (Awal=Nil) THEN
BEGIN
New(Baru);
Awal:=Baru;
Akhir:=Baru;
Awal^.Data:=Teks;
Awal^.Next:=Nil;
Akhir^.Next:=Nil;
END
ELSE
BEGIN
New(Baru);
Baru^.Data:=Teks;
Baru^.Next:=Awal;
Awal:=Baru;
END;
END;

PROCEDURE Tampilkan;
BEGIN
IF (Awal=Nil) THEN
BEGIN
WRITELN(‘Data Masih Kosong…’);
END
ELSE
BEGIN
Bantu:=Awal;
WHILE (Bantu<>Nil) DO
BEGIN
WRITELN(‘Datanya:’,Bantu^.Data);
Bantu:=Bantu^.Next;
END;
END;
END;

BEGIN
WHILE(pilihan<>4) DO
BEGIN
CLRSCR;
WRITELN(‘MENU PILIHAN LINKED LIST’);
WRITELN(‘========================’);
WRITELN(‘1. INSERT BELAKANG      ‘);
WRITELN(‘2. INSERT DEPAN         ‘);
WRITELN(‘3. TAMPILKAN            ‘);
WRITELN(‘4. SELESAI              ‘);
WRITELN(‘========================’);
WRITE(‘Pilihan : ‘); READLN(pilihan);
CASE pilihan of
1:InsertBelakang;
2:InsertDepan;
3:Tampilkan;
END;
READLN;
END;

END.