Program Pointer Single Linked List, Insert from the front, from behind, and insert adding Free Pascal
Introduce
Free Pascal is a compiler for the closely related programming language dialects, Pascal and Object Pascal. It is free software released under the GNU General Public License.
It supports its own Object Pascal dialect as well as the dialects of several other Pascal family compilers to a certain extent, including those of Turbo Pascal, Delphi, and some historical Macintosh compilers. The dialect is selected on a per-unit (module) basis, and more than one dialect can be used per program.
It follows a write once, compile anywhere philosophy, and is available for many CPU architectures and operating systems (see Targets). It supports integrated assembly language and an internal assembler in several dialects.[clarification needed]
Separate projects exist to facilitate developing cross-platform graphical user interface (GUI) applications, the most prominent one being the Lazarus integrated development environment (IDE).
source
What Will I Learn?
- insert data from the front
- data in the middle
- inserting data from behind
- delete data from the front
- delete data from the middle
- delete rear data
- prosudur print data
- data program
Requirements
- Your computer or leptop must already have Free pascal installed, if not you can mneginstal here
- Make sure your computer or leptop supports free pascal system tools
Difficulty
- Advanced
Tutorial Contents
My tutorial is using indonesian language.
No need to stale more, I will immediately display the tutorial that I mentioned earlier, below:
SINGLE LINKED LIST SIGN LINED LEARNING PROGRAM OF HOME, READ AND SIDE
Uses WinCrt;
Type
Pointer = ^TypeData;
TypeData = Record
Nilai : integer;
Berikutnya : Pointer;
End;
Var
List : Pointer;
- insert data from the front
Procedure Masuk_Depan(Var L : Pointer; X : Integer);
Var
Baru : Pointer;
Begin
New(Baru);
Baru^.Nilai := X; Baru^.Berikutnya := Nil; if L = Nil then L := Baru
else Begin
Baru^.Berikutnya :=L;
L :=Baru;
End;
End;
- insert data in the middle
Procedure Sisip_Tengah(Var L : Pointer; X, Y : Integer);
Var
Baru,Bantu : Pointer;
Begin
Bantu := L;
While Bantu^.berikutnya <> Nil Do
Begin
If Bantu^.Nilai = X Then
Begin
New(Baru);
Baru^.Nilai := Y;
Baru^.Berikutnya := Bantu^.Berikutnya;
Bantu^.Berikutnya := Baru;
End;
Bantu := Bantu^.Berikutnya;
End;
End;
- inserting data from behind
Procedure Masuk_Belakang(Var L : Pointer; X : Integer);
Var
Baru,Bantu : Pointer;
Begin
New(Baru);
Baru^.Nilai := X;
Baru^.Berikutnya := Nil;
Bantu := L;
While Bantu^.Berikutnya <> Nil Do
Bantu := Bantu^.Berikutnya;
Bantu^.Berikutnya := Baru;
End;
- delete data from the front
Procedure Hapus_Depan(Var L : Pointer);
Var
Baru : Pointer;
Begin Baru := L;
if L = Nil then Writeln('List Kosong...') else Begin
L := L^.Berikutnya; dispose(Baru);
End;
End;
- delete data from the middle
Procedure Hapus_Tengah(Var L : Pointer; X : Integer);
Var
Bantu,Hapus : Pointer;
Begin
Bantu := L;
if L = Nil then Writeln('List Kosong...') else Begin
Bantu := L;
New(Hapus);
While Bantu^.Berikutnya <> nil Do Begin
if Bantu^.Berikutnya^.nilai = X then begin
Hapus:=Bantu^.Berikutnya;
Bantu^.Berikutnya:=Hapus^.Berikutnya; dispose(Hapus); End else
Bantu:=Bantu^.Berikutnya;
End;
End;
End;
- delete data from behind
Procedure Hapus_Belakang(Var L : Pointer);
Var
Baru,bantu : Pointer;
Begin
Bantu := L;
if Bantu = Nil then Writeln('List Kosong...') else Begin
While Bantu^.Berikutnya^.Berikutnya <> nil do
Bantu := Bantu^.berikutnya;
New(Baru);
Baru := Bantu^.Berikutnya; Bantu^.Berikutnya:=nil; dispose(Baru);
End;
End;
- prosudur print data
Procedure Cetak(L : Pointer);
Var
Bantu : Pointer;
Begin
Bantu := L;
While Bantu <> Nil Do
Begin
Write(Bantu^.Nilai:3);
Bantu:=Bantu^.Berikutnya;
End;
End;
- main program
Var
Bil,Bil1 : integer;
JB : Char;
Begin
New(List);
List:=nil;
Jb := 'Y';
Writeln('MASUK DEPAN');
While UpCase(Jb)='Y' Do
Begin
Write('Masukkan Bilangan : '); Readln(Bil);
Masuk_Depan(List,Bil);
Write('Lagi[Y/T] ');Readln(Jb);
End;
Cetak(List);
Writeln;
Jb := 'Y';
Writeln('MASUK BELAKANG');
While UpCase(Jb)='Y' Do
Begin
Write('Masukkan Bilangan : '); Readln(Bil);
Masuk_Belakang(List,Bil);
Write('Lagi[Y/T] ');Readln(Jb);
End; Cetak(List); writeln; Jb := 'Y';
Writeln('MASUK DEPAN');
While UpCase(Jb)='Y' Do
Begin
Write('Masukkan Bilangan : '); Readln(Bil);
Masuk_Depan(List,Bil);
Write('Lagi[Y/T] ');Readln(Jb);
End;
Cetak(List);
Writeln;
Writeln('SISIP TENGAH');
Write('Masukkan Bilangan Yg akan disisip : ');
Readln(Bil1);
Write('Disisip Setelah Bilangan : ');
Readln(Bil);
Sisip_Tengah(List,Bil,Bil1);
Cetak(List); Writeln;
writeln('HAPUS DEPAN ');
Hapus_Depan(List);
Cetak(List); Writeln;
writeln('HAPUS BELAKANG');
Hapus_Belakang(List);
Cetak(List);
Writeln;
Writeln('HAPUS TENGAH');
Write('Masukkan Bilangan Yg akan dihapus : ');
Readln(Bil);
Hapus_Tengah(List,Bil);
Cetak(List);
Writeln;
End.
- below is the result
Hopefully the above tutorial useful for friends of all friends, thanks for everything,
follow me @feryhusaini
Your contribution cannot be approved because it does not follow the Utopian Rules.
Utopian rules state that:
This post does not contain any instructions and only presents code examples.
Quote from post:
Fortunately that's not true. Only English language tutorials are accepted.
You can contact us on Discord.
[utopian-moderator]
Hey @laxam, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!