I wrote this program a long time ago using Turbo Pascal to show how to create a Linked List in Pascal programming language.
I am currently accepting programming work inventory system, enrollment system, accounting system, payroll system, information system, website design and development using WordPress, IT projects, school and application development, programming projects, thesis, and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details. If you want to advertise on my website kindly contact me also in my email address also. Thank you.
My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.
Here in Bacolod City, Negros Occidental I also accepting computer repair, web development using WordPress, Computer Networking, and Arduino Project development at a very affordable price.
My personal website is http://www.jakerpomperada.com
My programming website is http://www.jakerpomperada.blogspot.com
I am also a book author you can purchase my books on computer programming and information technology in the following links below.
https://www.unlimitedbooksph.com/
Program Listing
PROGRAM LinkedListDemo(INPUT, OUTPUT);
CONST
Header = '------------- Main Menu --------------';
Separator = '--------------------------------------';
TYPE
DataString = STRING[30];
ListPointer = ^ListRecord;
ListRecord = RECORD
DataField :DataString;
NextField :ListPointer
END;
VAR
FirstPointer :ListPointer;
{ --------------------------- Procedure BuildList -------------------------- }
PROCEDURE BuildList(VAR FirstPointer :ListPointer;
DataItem :DataString);
{Note: FirstPointer is passed using the VAR keyword because it will be updated
by this procedure.}
VAR
ToolPointer :ListPointer;
BEGIN
NEW(ToolPointer);
ToolPointer^.DataField := DataItem;
ToolPointer^.NextField := FirstPointer;
FirstPointer := ToolPointer
END;
{ -------------------------- Procedure ReadList ---------------------------- }
PROCEDURE ReadList(FirstPointer :ListPointer);
VAR
CurrentPointer :ListPointer;
BEGIN
CurrentPointer := FirstPointer;
WHILE CurrentPointer <> NIL DO
BEGIN
WRITELN(CurrentPointer^.DataField);
CurrentPointer := CurrentPointer^.NextField
END;
WRITELN
END;
{ -------------------------- Procedure GetData------------------------------ }
PROCEDURE GetData(VAR FirstPointer :ListPointer);
{Note: FirstPointer is passed using the VAR keyword because it will be updated
when passed to BuildList procedure.}
VAR
Name :DataString;
BEGIN
WRITELN('Enter the names to be added to the list,',
' when finished hit ENTER.');
{ Read the first data item }
READLN(Name);
{ Check for end-of-data }
WHILE LENGTH(Name) <> 0 DO
BEGIN
BuildList(FirstPointer, Name);
READLN(Name)
END
END;
{ ------------------------- Procedure DisplayInfo -------------------------- }
PROCEDURE DisplayInfo(FirstPointer :ListPointer);
BEGIN
WRITELN(Separator);
WRITELN('The contents of the list: ');
ReadList(FirstPointer);
WRITE('Hit any key to continue...');
READLN
END;
{ --------------------------- Procedure Menu ------------------------------- }
PROCEDURE Menu;
VAR
Option :INTEGER;
BEGIN
WRITELN(Header);
WRITELN('1. Store data in a list.');
WRITELN('2. Display the list.');
WRITELN('3. Exit.');
WRITELN(Separator);
WRITE('Make a choice and press a number: ');
READLN(Option);
CASE Option OF
1 : GetData(FirstPointer);
2 : DisplayInfo(FirstPointer);
3 : Exit
END;
Menu
END;
{ ----------------------------- Main Program ------------------------------- }
BEGIN
{ Initialize an empty list }
FirstPointer := NIL;
menu
END.