2. Linked List
• Linked List can be defined as collection of
objects called nodes that are randomly stored
in the memory.
• A node contains two fields i.e. data stored at
that particular address and the pointer which
contains the address of the next node in the
memory.
• The last node of the list contains pointer to
the null.
3. Each node holds its own data and the address of
the next node hence forming a chain like structure.
Linked Lists are used to create trees and graphs.
4. Types of Link List
Following are the types of linked list
• Singly Linked List.
• Doubly Linked List.
• Circular Linked List.
29. Doubly Linked List
• A Doubly Linked List contains an extra memory
to store the address of the previous node,
together with the address of the next node and
data which are there in the singly linked list. So,
here we are storing the address of the next as
well as the previous nodes.
• The following is the structure of the node in the
Doubly Linked List(DLL):
33. Traversing Two Way Link List
Two way link list can be traversed in both the directions i.e.
in forward direction as well as backward direction.
34. Searching Two Way Link List
• Traverse the list until the pointer becomes null. Keep
shifting pointer to its next and increasing by +1.
• Compare each element of the list with the item which
is to be searched.
• If the item matched with any node value then the
location of that value I will be returned from the
function else NULL is returned.
35. Insertion of node in Two way Link List
There are three cases while inserting node
• Insertion at the Beginning
• Insertion at the End
• Insertion at the Particular position
45. Circular Link List
All Circular linked list is a list in which last node points
back to the first node instead of containing the Null pointer
in the next part of the last node.
46.
47.
48. Circular Singly Linked List
In a circular Singly linked list, the last node of the list
contains a pointer to the first node of the list. We can
have circular singly linked list as well as circular doubly
linked list.
We traverse a circular singly linked list until we reach
the same node where we started. The circular singly
liked list has no beginning and no ending. There is no
null value present in the next part of any of the nodes.
49. Operations on circular singly linked list
SN Operation Description
1 Insertion at beginning Adding a node in circular singly
linked list at the beginning.
2 Insertion at end Adding a node in circular singly
linked list at the end.
3 Deletion at beginning Removing a node in circular singly
linked list from beginning.
4 Deletion at end Removing a node in circular singly
linked list at the end.
5
Traversing
Visiting each element of the list at
least once in order to perform some
specific operation.
50. Circular Doubly Linked List
Circular doubly linked list is a more complexed type of
data structure in which a node contain pointers to its
previous node as well as the next node. Circular doubly
linked list doesn't contain NULL in any of the node. The
last node of the list contains the address of the first node
of the list. The first node of the list also contain address
of the last node in its previous pointer.
51. Operations on circular doubly linked list
:
SN Operation Description
1 Insertion at beginning Adding a node in circular doubly
linked list at the beginning.
2 Insertion at end Adding a node in circular doubly
linked list at the end.
3 Deletion at beginning Removing a node in circular doubly
linked list from beginning.
4 Deletion at end Removing a node in circular doubly
linked list at the end.
52. Advantages of a Circular linked list
• The list can be traversed from any node.
• Circular lists are the required data
structure when we want a list to be
accessed in a circle or loop.
• We can easily traverse to its previous
node in a circular linked list, which is not
possible in a singly linked list.
53. Disadvantages of Circular linked list
• If not traversed carefully, then we could
end up in an infinite loop because here
we don't have any NULL value to stop
the traversal.
• Operations in a circular linked list are
complex as compared to a singly linked
list and doubly linked list.