Professional Documents
Culture Documents
INTRODUCTION
3
• Linked list is a liner data structure consisting of
elements called nodes where each node is
composed of two parts:
• Information part .
• Link part (called next pointer part)
• The information part contains user supplied data
and the link part is a pointer which points to the
next node in the linked list.
• The link part of the last node is set to NULL that
marks the end of the list
Representation of Link List in Memory
12 Nelson 9
• A linked list may not contain any node at all.Such a
list with no nodes at all is called an empty list.The
empty list is represented by setting the HEAD
pointer to NULL value.
• START or HEAD pointer is a special pointer which
points to the first node of the linked list.
• Linked list is a dynamic data structure as number of
elements are not pre-defined.Any number of
elements can be added or deleted easily.
• Linked list is also a linear data strucutre.
• Although the nodes are stored independently (i.e at
different memory locations),linearity is provided by
the links that binds them together.
• Linked lists are useful in applications where access
of elements is not at random and dynamic memory
allocation and deallocation of data elements are
frequently needed.
OPERATIONS ON LINKED LIST
BACK Pointer
FORE Pointer
INFO Field
A two way list is a linear collection of data elements, called nodes, where
each node N is divided into three parts:
64
TYPES DOUBLE LINKED LIST
• DOUBLE_DEL(HEAD,TAIL,LOC): Given a
doubly linked list with the address of the leftmost
and rightmost nodes given by pointers HEAD and
TAIL resp. This algo deletes the node whose address
is contained in pointer variable LOC . The forward and
backward links of node are denoted by FLINK and
PLINK respectively.
1.[empty list?]
IF TAIL=NULL, then
Write ”Underflow”.
return
[End of if structure]
2.[Delete Node]
IF HEAD=TAIL, then [Only one node in the list]
HEADTAILNULL
Else If LOC=HEAD then [Leftmost node being deleted]
a)HEAD FLINK(HEAD)
b) PLINK(HEAD)NULL
Else If LOC=TAIL then[Rightmost node being deleted]
a) TAILPLINK(TAIL)
b) FLINK(TAIL)NULL
Else[Node being deleted appear somewhere in the middle of the list]
a) FLINK(PLINK(LOC))FLINK(LOC)
b) PLINK(FLINK(LOC))PLINK(LOC)
[end of if structure]
3. [Return deleted node to free storage list]
a) FLINK(LOC)-AVAIL
b) AVAIL LOC
4. Return
INSERTION IN LINKED LIST
Insertion IN Doubly Linked List
• DOUBL_INS(HEAD, TAIL,LOC, ITEM): Given doubly linked list whose left-most and
right-most node addresses are given by pointer variable HEAD and TAIL resp. This algo
insert a node to the left of specified node with address given by pointer variable LOC . Here
NEW is local pointer variable that points to new node to be inserted. The info to be entered
in the new node is contained in ITEM. The forward and backward links of node are denoted
by FLINK and PLINK resp.
1. IF AVAIL=NULL, then [Avail list is empty]
Write” Overflow”
Return
[end of if structure]
2. NEWAVAIL [create new node]
3. AVAILFLINK(AVAIL) [Update AVAIL]
4. INFO(NEW)ITEM [copy item into info part of new node]
5.[inserting new node in empty list?]
IF HEAD=NULL, then
a) PLINK(NEW)FLINK(NEW)NULL
b) HEADTAILNEW
return
[end of if structure]
6.[Leftmost insertion]
IF LOC=HEAD , then
a)PLINK(NEW)NULL
b) FLINK(NEW)LOC
c) PLINK(LOC)NEW
d) HEADNEW
return
[end of id structure]
7.[Insertion somewhere in the middle of list]
a)PLINK(NEW)PLINK(LOC)
b) FLINK(NEW)LOC
c) PLINK(LOC)NEW
d) FLINK((PLINK(NEW))NEW
8. Return
THANK YOU