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 :
It has three 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
List
This Reference has the value of (nil) in the last element in the
Linked List.
3. The References which refers to the previous element in the
Linked List
This Reference has the value of (nil) in the first element in the
Linked List.
Program test1;
Type
D_P = ^D_R;
D_R = record
num : integer;
next,prev : D_P;
end;
Now let’s meet with some procedures
which are used in DLL
It has three cases:
1. Insert an element in the first of DLL
2. Insert an element in the last of DLL
3. Insert an element anywhere else
Procedure Insert (var L_S,L_E: D_P; numb: integer)
Var
S,temp : D_P; located : boolean
Begin
new(temp);
temp^.num := numb;
temp^.next := nil;
temp^.prev := nil;
if (L_S = nil) then
begin
L_S := temp; L_E := temp;
end
else
begin
S := L_S; located := false;
while (S <> nil) and (not located) do
begin
if (S^.num < numb) then
S := S^.next;
else
located := true;
end;
temp^.next := S;
if (L_S = S) then
begin
L_S^.prev := temp;
L_S := temp;
end
else if (S = nil) then
begin
L_E^.next := temp;
temp^.prev := L_E;
L_E := temp;
end
else
begin
S^.prev^.next := temp;
temp^.prev := S^.prev;
S^.prev := temp;
end;
end;
End;
It has three cases:
1. Delete the first element
2. Delete the last element
3. Delete any other element
Procedure Delete(var L_S,L_E: D_P; numb: integer;
flag: char)
Var
S,temp : D_P;
Begin
if (L_S = nil) then flag := ‘0’;
if (numb = L_S^.num) then
begin
flag := ‘1’;
temp := L_S;
L_S := L_S^.next;
L_S^.prev := nil;
dispose(temp);
end
else if (numb = L_E^.num) then
begin
flag := ‘1’;
temp := L_E;
L_E := L_E^.prev;
L_E^.next := nil;
dispose(temp);
end
else
begin
S := L_S;
while (S <> nil) and (S^.num <> numb) do
S := S^.next
if (S = nil) then flag := ‘2’
else
begin
flag := ‘1’;
S^.next^.prev := S^.prev;
S^.prev^.next := S^.next;
dispose(S);
end;
end;
End;
Double linked list c8

Double linked list c8

  • 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.
    It has threeelements: 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 List This Reference has the value of (nil) in the last element in the Linked List. 3. The References which refers to the previous element in the Linked List This Reference has the value of (nil) in the first element in the Linked List.
  • 5.
    Program test1; Type D_P =^D_R; D_R = record num : integer; next,prev : D_P; end; Now let’s meet with some procedures which are used in DLL
  • 6.
    It has threecases: 1. Insert an element in the first of DLL 2. Insert an element in the last of DLL 3. Insert an element anywhere else
  • 7.
    Procedure Insert (varL_S,L_E: D_P; numb: integer) Var S,temp : D_P; located : boolean Begin new(temp); temp^.num := numb; temp^.next := nil; temp^.prev := nil; if (L_S = nil) then begin L_S := temp; L_E := temp; end
  • 8.
    else begin S := L_S;located := false; while (S <> nil) and (not located) do begin if (S^.num < numb) then S := S^.next; else located := true; end; temp^.next := S;
  • 9.
    if (L_S =S) then begin L_S^.prev := temp; L_S := temp; end else if (S = nil) then begin L_E^.next := temp; temp^.prev := L_E; L_E := temp; end
  • 10.
    else begin S^.prev^.next := temp; temp^.prev:= S^.prev; S^.prev := temp; end; end; End;
  • 11.
    It has threecases: 1. Delete the first element 2. Delete the last element 3. Delete any other element
  • 12.
    Procedure Delete(var L_S,L_E:D_P; numb: integer; flag: char) Var S,temp : D_P; Begin if (L_S = nil) then flag := ‘0’; if (numb = L_S^.num) then begin flag := ‘1’; temp := L_S; L_S := L_S^.next; L_S^.prev := nil; dispose(temp); end
  • 13.
    else if (numb= L_E^.num) then begin flag := ‘1’; temp := L_E; L_E := L_E^.prev; L_E^.next := nil; dispose(temp); end
  • 14.
    else begin S := L_S; while(S <> nil) and (S^.num <> numb) do S := S^.next if (S = nil) then flag := ‘2’ else begin flag := ‘1’; S^.next^.prev := S^.prev; S^.prev^.next := S^.next; dispose(S); end; end; End;