Top Banner
Pascal Programming Language Omar ElSabek & Fayez G hazzawi IT Engineering 3 th year UNKNOWN Department programming II
15

Double linked list c8

Apr 14, 2017

Download

Education

Omar Al-Sabek
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Double linked list c8

Pascal Programming Language

Omar ElSabek & Fayez GhazzawiIT Engineering3th year – UNKNOWN Department

programming II

Page 2: Double linked list c8

Sets

Record

Files (Text & Binary)

Pointers

Linked Lists

Unit

Course Index :

Page 3: Double linked list c8
Page 4: Double linked list c8

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 ListThis 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 ListThis Reference has the value of (nil) in the first element in the Linked List.

Page 5: Double linked list c8

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

Page 6: Double linked list c8

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

Page 7: Double linked list c8

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

Page 8: Double linked list c8

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;

Page 9: Double linked list c8

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

Page 10: Double linked list c8

else

begin

S^.prev^.next := temp;

temp^.prev := S^.prev;

S^.prev := temp;

end;

end;

End;

Page 11: Double linked list c8

It has three cases:

1. Delete the first element

2. Delete the last element

3. Delete any other element

Page 12: Double linked list c8

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

Page 13: Double linked list c8

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

Page 14: Double linked list c8

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;

Page 15: Double linked list c8