Pascal Programming Language
Omar ElSabek & Fayez Ghazzawi
IT Engineering
3th year – UNKNOWN Department
programming II
Sets
Record
Files (Text & Binary)
Pointers
Linked Lists
Unit
Course Index :
So the Linked List is:
Juuust like an array with unlimited elements ,because all the
elements are reserved inside the memory in “RunTime”
So the Linked Lists were born so there is no constant size for
any array
We can say that the Linked List is an array with inconstant size
There are two forms for Linked Lists:
1. Single Linked Lists “SLL”
2. Double Linked Lists “DLL”
It has two elements:
1. TheVariable(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 List
This Reference has the value of (nil) in the last element in
the Linked List
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
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
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
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;
temp^.next := S;
if (L_S = S) then
L_S := temp
else
P^.next := temp;
end;
End.
It has two cases:
1. Delete the first element
2. Delete any other element
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
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;
if (not located) then
flag := ‘2’
else
begin
flag := ‘1’;
temp := S^.next;
S^.next := temp^.next;
dispose(temp);
end;
end;
End.
Linked lists c7

Linked lists c7

  • 1.
    Pascal Programming Language OmarElSabek & Fayez Ghazzawi IT Engineering 3th year – UNKNOWN Department programming II
  • 2.
    Sets Record Files (Text &Binary) Pointers Linked Lists Unit Course Index :
  • 4.
    So the LinkedList is: Juuust like an array with unlimited elements ,because all the elements are reserved inside the memory in “RunTime” So the Linked Lists were born so there is no constant size for any array We can say that the Linked List is an array with inconstant size
  • 5.
    There are twoforms for Linked Lists: 1. Single Linked Lists “SLL” 2. Double Linked Lists “DLL”
  • 6.
    It has twoelements: 1. TheVariable(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 List This Reference has the value of (nil) in the last element in the Linked List
  • 7.
    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
  • 8.
    It has threecases: 1. Insert an element in the first of SLL 2. Insert an element in the last of SLL 3. Insert an element anywhere else
  • 9.
    Procedure Insert (varL_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
  • 10.
    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;
  • 11.
    temp^.next := S; if(L_S = S) then L_S := temp else P^.next := temp; end; End.
  • 12.
    It has twocases: 1. Delete the first element 2. Delete any other element
  • 13.
    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
  • 14.
    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;
  • 15.
    if (not located)then flag := ‘2’ else begin flag := ‘1’; temp := S^.next; S^.next := temp^.next; dispose(temp); end; end; End.