linked lists c7
TRANSCRIPT
![Page 1: Linked lists c7](https://reader031.vdocument.in/reader031/viewer/2022021922/5873fa1a1a28abb1528b6c45/html5/thumbnails/1.jpg)
Pascal Programming Language
Omar ElSabek & Fayez GhazzawiIT Engineering3th year – UNKNOWN Department
programming II
![Page 2: Linked lists c7](https://reader031.vdocument.in/reader031/viewer/2022021922/5873fa1a1a28abb1528b6c45/html5/thumbnails/2.jpg)
Sets
Record
Files (Text & Binary)
Pointers
Linked Lists
Unit
Course Index :
![Page 3: Linked lists c7](https://reader031.vdocument.in/reader031/viewer/2022021922/5873fa1a1a28abb1528b6c45/html5/thumbnails/3.jpg)
![Page 4: Linked lists c7](https://reader031.vdocument.in/reader031/viewer/2022021922/5873fa1a1a28abb1528b6c45/html5/thumbnails/4.jpg)
So the Linked List is:
Juuust like an array with unlimited elements ,because all the elements are reserved inside the memory in “Run Time”So the Linked Lists were born so there is no constant size for any arrayWe can say that the Linked List is an array with inconstant size
![Page 5: Linked lists c7](https://reader031.vdocument.in/reader031/viewer/2022021922/5873fa1a1a28abb1528b6c45/html5/thumbnails/5.jpg)
There are two forms for Linked Lists:
1. Single Linked Lists “SLL”
2. Double Linked Lists “DLL”
![Page 6: Linked lists c7](https://reader031.vdocument.in/reader031/viewer/2022021922/5873fa1a1a28abb1528b6c45/html5/thumbnails/6.jpg)
It has two elements:
1. The Variable(s) with Data type(s) “the same with all the Linked List elements”
2. The References which refers to the next element in the Linked ListThis Reference has the value of (nil) in the last element in the Linked List
![Page 7: Linked lists c7](https://reader031.vdocument.in/reader031/viewer/2022021922/5873fa1a1a28abb1528b6c45/html5/thumbnails/7.jpg)
Program test1;
Type
L_P = ^L_R;
L_R = record
num : integer;
next : L_P;
end;
Now let’s meet with some procedures which are used in SLL
![Page 8: Linked lists c7](https://reader031.vdocument.in/reader031/viewer/2022021922/5873fa1a1a28abb1528b6c45/html5/thumbnails/8.jpg)
It has three cases:
1. Insert an element in the first of SLL
2. Insert an element in the last of SLL
3. Insert an element anywhere else
![Page 9: Linked lists c7](https://reader031.vdocument.in/reader031/viewer/2022021922/5873fa1a1a28abb1528b6c45/html5/thumbnails/9.jpg)
Procedure Insert (var L_S: L_P; numb: integer)
Var
P,S,temp : L_P; located : boolean
Begin
new(temp);
temp^.num := numb;
temp^.next := nil;
if (L_S = nil) then
L_S := temp
![Page 10: Linked lists c7](https://reader031.vdocument.in/reader031/viewer/2022021922/5873fa1a1a28abb1528b6c45/html5/thumbnails/10.jpg)
else
begin
S := L_S;
located := false;
while (S <> nil) and (not located) do
begin
if (S^.num < numb) then
begin
P := S;
S := S^.next;
end
else
located := true;
end;
![Page 11: Linked lists c7](https://reader031.vdocument.in/reader031/viewer/2022021922/5873fa1a1a28abb1528b6c45/html5/thumbnails/11.jpg)
temp^.next := S;
if (L_S = S) then
L_S := temp
else
P^.next := temp;
end;
End.
![Page 12: Linked lists c7](https://reader031.vdocument.in/reader031/viewer/2022021922/5873fa1a1a28abb1528b6c45/html5/thumbnails/12.jpg)
It has two cases:
1. Delete the first element
2. Delete any other element
![Page 13: Linked lists c7](https://reader031.vdocument.in/reader031/viewer/2022021922/5873fa1a1a28abb1528b6c45/html5/thumbnails/13.jpg)
Procedure Delete(var L_S: L_P; numb: integer;
flag: char)
Var
S,temp : L_P; located : boolean
Begin
if (numb = L_S^.num) then
begin
flag := ‘1’;
temp := L_S;
L_S := L_S^.next;
dispose(temp);
end
![Page 14: Linked lists c7](https://reader031.vdocument.in/reader031/viewer/2022021922/5873fa1a1a28abb1528b6c45/html5/thumbnails/14.jpg)
else
begin
S := L_S;
located := false;
while (S^.next <> nil) and (not located) do
begin
if (S^.next^.num <> numb) then
S := S^.next
else
located := true;
end;
![Page 15: Linked lists c7](https://reader031.vdocument.in/reader031/viewer/2022021922/5873fa1a1a28abb1528b6c45/html5/thumbnails/15.jpg)
if (not located) then
flag := ‘2’
else
begin
flag := ‘1’;
temp := S^.next;
S^.next := temp^.next;
dispose(temp);
end;
end;
End.
![Page 16: Linked lists c7](https://reader031.vdocument.in/reader031/viewer/2022021922/5873fa1a1a28abb1528b6c45/html5/thumbnails/16.jpg)