0% found this document useful (0 votes)
248 views2 pages

Program Lifo Dengan Pascal

This document contains the code for a linked list program in Pascal. It defines procedures for building a linked list, reading the linked list, getting user input data, displaying the list, and writing the list to a text file. It also defines a menu procedure to call the other procedures and allow the user to interact with and use the linked list program.

Uploaded by

Deny Nova
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
248 views2 pages

Program Lifo Dengan Pascal

This document contains the code for a linked list program in Pascal. It defines procedures for building a linked list, reading the linked list, getting user input data, displaying the list, and writing the list to a text file. It also defines a menu procedure to call the other procedures and allow the user to interact with and use the linked list program.

Uploaded by

Deny Nova
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Nama : Renny Dwi Yuni A

Kelas : 2B – Sore
Nim : 12108000076

PROGRAM UTAMA KONSEP

PROGRAM LinkedList1; Deklarasi Type sebuah Program Lifo


Uses Wincrt;
ListPointer = Pointer
CONST ListRecord = RecPoint
Header ='------------ Menu Utama ------------'; DataField = Isi
Separator ='------------------------------------'; FirstPointer = Head
TYPE
DataString = STRING[30];
ListPointer = ^ListRecord;
ListRecord = RECORD
DataField : DataString;
NextField : ListPointer
END;
VAR FirstPointer : ListPointer;

PROCEDURE BuildList(VAR FirstPointer : ListPointer; ToolPointer = Now


DataItem : DataString);
VAR Begin
ToolPointer : ListPointer; New(Now);
BEGIN Now^.Isi := Elemen;
NEW(ToolPointer); Now^.Next := Head;
ToolPointer^.DataField := DataItem; Head := Now;
ToolPointer^.NextField := FirstPointer; End;
FirstPointer:=ToolPointer
END;

PROCEDURE ReadList (FirstPointer : ListPointer); CurrentPointer = Now


VAR CurrentPointer : ListPointer; Begin
BEGIN Now := Head;
CurrentPointer := FirstPointer; while Now <> nil do
WHILE CurrentPointer <> NIL DO begin
BEGIN writeln (Now^.Isi);
WRITELN(CurrentPointer^.DataField); Now := Now^.next
CurrentPointer := CurrentPointer^.NextField end;
END; writeln
WRITELN end;
END;

PROCEDURE GetData(VAR FirstPointer:ListPointer);


VAR Name:DataString;
BEGIN
WRITELN('Masukkan nama yang akan ditambahkan lalu tekan
ENTER jika selesai.');
READLN(Name); Procedure Menginputkan Data
WHILE LENGTH(Name) <> 0 DO
BEGIN
BuildList(FirstPointer,Name); READLN(Name)
END
END;
PROCEDURE DisplayInfo(FirstPointer:ListPointer);
BEGIN
WRITELN(Separator);
WRITELN('Isi dari daftar:'); Procedure Menampilkan Hasil Inputan / Data
ReadList(FirstPointer);
WRITE('Tekan sembarang tombol untuk lanjut...');
READLN
END;

PROCEDURE Cetak(firstpointer:listPointer);
var posisi:text; Prosedure Mengalamatkan Hasil Program ke format .txt
CurrentPointer : ListPointer;
begin Assign (posisi,’dafnama.txt’);
assign(posisi,'dafnama.txt'); Now := Head
rewrite(posisi); While Now <> Nil do
writeln(posisi,'Tertulis dengan Indah sebagai berikut :'); Begin
writeln(posisi); Writeln (posisi,Now.^Isi);
Writeln(posisi,separator); Now := Now^.Next
Writeln(posisi,'Isi dari daftar'); End;
writeln(posisi);
CurrentPointer := FirstPointer; Note:
WHILE CurrentPointer <> NIL DO Program diatas merupakan format penulisan di notepad
sama dengan procedure ReadList untuk Find First dan
BEGIN Find Next
WRITELN(posisi,CurrentPointer^.DataField);
CurrentPointer := CurrentPointer^.NextField
END;
writeln;
writeln('Data telah di tulis ke dafnama.txt, tinggal di lihat
saja...');
readln;
close(posisi);
end;

PROCEDURE Menu;
VAR Option : INTEGER;
BEGIN
WRITELN(Header);
WRITELN('1. Simpan data pada daftar.');
WRITELN('2. Tampilan daftar.');
Writeln('3. Tulis data ke teks '); Membuat Tampilan Menu Bar Pada Hasil
WRITELN('4. Keluar.');
WRITELN(Separator); CASE Option OF
WRITE('Pilihan --> '); 1 : GetData(FirstPointer);
READLN(Option); 2 : DisplayInfo(FirstPointer);
CASE Option OF 3 : cetak(firstpointer);
1 : GetData(FirstPointer); 4 : exit;
2 : DisplayInfo(FirstPointer);
3 : cetak(firstpointer); Untuk Memanggil Procedure-Procedure untuk
4 : exit; menjalankan Menu
END;
Menu
END;

BEGIN
FirstPointer := NIL;
menu Bagian Program Utama !
END.

You might also like