written 8.6 years ago by | • modified 8.6 years ago |
i) Insertion (all cases) - ii) Traversal (forward and backward) -
Marks: 10 M
Year: Dec 2013, May 2013, Dec 2012
written 8.6 years ago by | • modified 8.6 years ago |
i) Insertion (all cases) - ii) Traversal (forward and backward) -
Marks: 10 M
Year: Dec 2013, May 2013, Dec 2012
written 8.6 years ago by |
1. Doubly linked list:
i. A doubly linked list is one in which all nodes are linked together by multiple links which help in accessing both the successor and predecessor node for any arbitrary node within the list.
ii. Every nodes in the doubly linked list has three fields: LeftPointer, RightPointer and DATA.
iii. The last node has a next link with value NULL, marking the end of the list, and the first node has a prev link with the value NULL. The start of the list is marked by the head pointer.
iv. Diagram:
Figure 1: Doubly linked list
2. Algorithm:
Assume that START is the first element in the linked list and TAIL is the last element of linked list.
i. Insert At Beginning
NewNode → Data = DATA NewNode →Lpoint =NULL
IF START IS NULL NewNode→ Rpoint = NULL
ii. Insertion at location:
(a) Create a New Node
(b) NewNode → DATA = DATA
(c) NewNode → RPoint = TEMP → RPoint
(d) NewNode → LPoint = TEMP
(e) (TEMP → RPoint) → LPoint = NewNode
(f ) TEMP → RPoint = New Node
Else
(a) Display “Position NOT found”
iii. Insert at End
a. START = NewNode
b. NewNode → LPoint=NULL
a. TEMP = START
b. While (TEMP → Next not equal to NULL)
i. TEMP = TEMP → Next
c. TEMP → RPoint = NewNode
d. NewNode → LPoint = TEMP
iv. Forward Traversal
a) Display “The list is Empty”
b) Stop
v. Backward Traversal