0% found this document useful (0 votes)
6 views

LINKLIST

Uploaded by

msd130105
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

LINKLIST

Uploaded by

msd130105
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

IT - 12.

Data Structure & Algorithms Unit 1: Array / List

UNIT - 2
Linked Lists

• Introduction & Definition of Linked Lists:


A linked list, or one-way list, is a linear collection of data elements, called nodes,
where thelinear order is given by means of pointers. That is, each node is divided into
two parts:
• The first part contains the information of the element, and
• The second part, called the link field or nextpointer field, contains the address of
thenext node in the list.

In the above figure each node is pictured with two parts.


• The left part represents the information part of the node, which may contain an
entirerecord of data items.
• The right part represents the nextpointer field of the node
• An arrow drawn from a node to the next node in the list.
• The pointer of the last node contains a special value, called the null pointer,
which isany invalid address.

A pointer variable called START or HEAD which contains the address of the first node.
A special case is the list that has no nodes, such a list is called the null list or empty list
and isdenoted by the null pointer in the variable START.

Importance / Advantages of Linked List:


Here are a few advantages of a linked list that is listed below, it will help you understand
why it is necessary to know.
• Dynamic Data structure: The size of memory can be allocated or de-allocated at run
time based on the operation insertion or deletion.
• Ease of Insertion/Deletion: The insertion and deletion of elements are simpler than
arrays since no elements need to be shifted after insertion and deletion, Just the address
needed to be updated.
Prof. Kiran Shejul Dr. DYPIMED
IT - 12. Data Structure & Algorithms Unit 1: Array / List
• Efficient Memory Utilization: As we know Linked List is a dynamic data structure the
size increases or decreases as per the requirement so this avoids the wastage of
memory.
• Implementation: Various advanced data structures can be implemented using a linked
list like a stack, queue, graph, hash maps, etc.

Disadvantages of Linked List:

• Memory usage: More memory is required in the linked list as compared to an array.
Because in a linked list, a pointer is also required to store the address of the next element
and it requires extra memory for itself.
• Traversal: In a Linked list traversal is more time-consuming as compared to an array.
Direct access to an element is not possible in a linked list as in an array by index. For
example, for accessing a node at position n, one has to traverse all the nodes before it.
• Reverse Traversing: In a singly linked list reverse traversing is not possible, but in the
case of a doubly-linked list, it can be possible as it contains a pointer to the previously
connected nodes with each node. For performing this extra memory is required for the
back pointer hence, there is a wastage of memory.
• Random Access: Random access is not possible in a linked list due to its dynamic memory
allocation.
• Lower efficiency at times: For certain operations, such as searching for an element or
iterating through the list, can be slower in a linked list.
• Complex implementation: The linked list implementation is more complex when
compared to array. It requires a complex programming understanding.
• Difficult to share data: This is because it is not possible to directly access the memory
address of an element in a linked list.
• Not suited for small dataset: Cannot provide any significant benefits on small dataset
compare to that of an array.

Prof. Kiran Shejul Dr. DYPIMED


IT - 12. Data Structure & Algorithms Unit 1: Array / List
• Memory Allocation in a Linked List:

Let LIST be a linked list. Then LIST will be maintained in memory as follows.

1. LIST requires two linear arrays such as INFO and LINK-such that INFO[K] and
LINK[K] contains the information part and the nextpointer field of a node of LIST.
2. LIST also requires a variable name such as START which contains the location of
the beginning of the list, and a nextpointer sentinel denoted by NULL-which
indicates the end of the list.
3. The subscripts of the arrays INFO and LINK will be positive, so choose NULL =
0, unless otherwise stated.

The following examples of linked lists indicate that the nodes of a list need not occupy
adjacent elements in the arrays INFO and LINK, and that more than one list may be
maintained in thesame linear arrays INFO and LINK. However, each list must have its own
pointer variable giving the location of its first node.

START=9 INFO[9]=N
LINK[3]=6 INFO[6]=V
LINK[6]=11 INFO[11]=E
LINK[11]=7 INFO[7]= X
LINK[7]=10 INFO[10]= I
LINK[10]=4 INFO[4]= T
LINK[4]= NULL value, So the list has ended
Prof. Kiran Shejul Dr. DYPIMED
IT - 12. Data Structure & Algorithms Unit 1: Array / List

• The maintenance of linked lists in memory assumes the possibility of inserting


new nodes into the lists and hence requires some mechanism which provides unused
memory space for the new nodes.
• Mechanism is required whereby the memory space of deleted nodes becomes
available for future use.
• Together with the linked lists in memory, a special list is maintained which consists
of unused memory cells. This list, which has its own pointer, is called the list of
available space or the free storage list or the free pool.

Suppose linked lists are implemented by parallel arrays and insertions and deletions are to
be performed linked lists. Then the unused memory cells in the arrays will also be linked
togetherto form a linked list using AVAIL as its list pointer variable. Such a data structure
will be denoted by
LIST (INFO, LINK, START,
AVAIL)

Prof. Kiran Shejul Dr. DYPIMED


IT - 12. Data Structure & Algorithms Unit 1: Array / List
Overflow

• Sometimes new data are to be inserted into a data structure but there is no available
space, i.e., the free-storage list is empty. This situation is usually called overflow.

• The programmer may handle overflow by printing the message OVERFLOW. In


such a case, the programmer may then modify the program by adding space to the
underlying arrays.
• Overflow will occur with linked lists when AVAIL = NULL and there is an
insertion.

Underflow

• The term underflow refers to the situation where one wants to delete data from a
datastructure that is empty.
• The programmer may handle underflow by printing the message UNDERFLOW.
• The underflow will occur with linked lists when START = NULL and there is a
deletion.

Prof. Kiran Shejul Dr. DYPIMED


IT - 12. Data Structure & Algorithms Unit 1: Array / List

• Types of Linked Lists

• Singly Linked List:


It is the commonly used linked list in programs. If we are talking about the linked list, it means
it is a singly linked list. The singly linked list is a data structure that contains two parts, i.e.,
one is the data part, and the other one is the address part, which contains the address of the next
or the successor node. The address part in a node is also known as a pointer.

Suppose we have three nodes, and the addresses of these three nodes are 100, 200 and 300
respectively. The representation of three nodes as a linked list is shown in the below figure:

We can observe in the above figure that there are three different nodes having address 100, 200
and 300 respectively. The first node contains the address of the next node, i.e., 200, the second
node contains the address of the last node, i.e., 300, and the third node contains the NULL
value in its address part as it does not point to any node. The pointer that holds the address of
the initial node is known as a head pointer.

The linked list, which is shown in the above diagram, is known as a singly linked list as it
contains only a single link. In this list, only forward traversal is possible;

we cannot traverse in the backward direction as it has only one link in the list.

Prof. Kiran Shejul Dr. DYPIMED


IT - 12. Data Structure & Algorithms Unit 1: Array / List
• Operations on a Singly Linked List
A singly linked list allows various operations to be performed on its nodes. These operations
are essential for managing and manipulating the data stored in the list.

Insertion
The insertion into a singly linked list can be performed at different positions. Based on the
position of the new node being inserted, the insertion is categorized into the following
categories.

Insertion at beginning :
Inserting a new element into a singly linked list at beginning is quite simple. We just need to
make a few adjustments in the node links. There are the following steps which need to be
followed in order to insert a new node in the list at beginning.

Algorithm to Insert Element at the beginning of Linked List

Step 1: IF PTR = NULL


Write OVERFLOW
Go to Step 7
[END OF IF]
Step 2: SET NEW_NODE = PTR
Step 3: SET PTR = PTR → NEXT
Step 4: SET NEW_NODE → DATA = VAL
Step 5: SET NEW_NODE → NEXT = HEAD
Step 6: SET HEAD = NEW_NODE
Step 7: EXIT

Insertion at end of Linked List:


In order to insert a node at the last, there are two following scenarios which need to be
mentioned.

Case 1: The node is being added to an empty list

The condition (head == NULL) gets satisfied. Hence, we just need to allocate the space for the
node by using malloc statement in C. Data and the link part of the node are set up by using the
following statements.

Prof. Kiran Shejul Dr. DYPIMED


IT - 12. Data Structure & Algorithms Unit 1: Array / List
ptr->data = item;
ptr -> next = NULL;

Since, ptr is the only node that will be inserted in the list hence, we need to make this node
pointed by the head pointer of the list. This will be done by using the following Statements.

Case 2: The node is being added to the end of the linked list

The condition Head = NULL would fail, since Head is not null. Now, we need to declare a
temporary pointer temp in order to traverse through the list. temp is made to point the first node
of the list.

Temp = head

Then, traverse through the entire linked list using the statements:

while (temp → next != NULL)


temp = temp → next;
At the end of the loop, the temp will be pointing to the last node of the list. Now, allocate the
space for the new node, and assign the item to its data part. Since, the new node is going to be
the last node of the list hence, the next part of this node needs to be pointing to the null. We
need to make the next part of the temp node (which is currently the last node of the list) point
to the new node (ptr) .
temp = head;
while (temp -> next != NULL)
{
temp = temp -> next;
}
temp->next = ptr;
ptr->next = NULL;

Algorithm to Insert Element at the end of Linked List

Step 1: IF PTR = NULL Write OVERFLOW


Go to Step 1
[END OF IF]
Step 2: SET NEW_NODE = PTR
Step 3: SET PTR = PTR - > NEXT

Prof. Kiran Shejul Dr. DYPIMED


IT - 12. Data Structure & Algorithms Unit 1: Array / List
Step 4: SET NEW_NODE - > DATA = VAL
Step 5: SET NEW_NODE - > NEXT = NULL
Step 6: SET PTR = HEAD
Step 7: Repeat Step 8 while PTR - > NEXT != NULL
Step 8: SET PTR = PTR - > NEXT
[END OF LOOP]
Step 9: SET PTR - > NEXT = NEW_NODE
Step 10: EXIT

Insertion in singly linked list after specified Node:


In order to insert an element after the specified number of nodes into the linked list, we
need to skip the desired number of elements in the list to move the pointer at the position
after which the node will be inserted. This will be done by using the following statements.
emp=head;
for(i=0;i<loc;i++)
{
temp = temp->next;
if(temp == NULL)
{
return;
}
}
Allocate the space for the new node and add the item to the data part of it. This will be done
by using the following statements.
ptr = (struct node *) malloc (sizeof(struct node));
ptr->data = item;

Now, we just need to make a few more link adjustments and our node at will be inserted at
the specified position. Since, at the end of the loop, the loop pointer temp would be pointing
to the node after which the new node will be inserted. Therefore, the next part of the new
node ptr must contain the address of the next part of the temp (since, ptr will be in between
temp and the next of the temp). This will be done by using the following statements.
ptr→ next = temp → next

now, we just need to make the next part of the temp, point to the new node ptr. This will
insert the new node ptr, at the specified position.
temp ->next = ptr;

Prof. Kiran Shejul Dr. DYPIMED


IT - 12. Data Structure & Algorithms Unit 1: Array / List

Algorithm to Insert Element after specified Node

STEP 1: IF PTR = NULL


WRITE OVERFLOW
GOTO STEP 12
END OF IF
STEP 2: SET NEW_NODE = PTR
STEP 3: NEW_NODE → DATA = VAL
STEP 4: SET TEMP = HEAD
STEP 5: SET I = 0
STEP 6: REPEAT STEP 5 AND 6 UNTIL I
STEP 7: TEMP = TEMP → NEXT
STEP 8: IF TEMP = NULL
WRITE "DESIRED NODE NOT PRESENT"
GOTO STEP 12
END OF IF
END OF LOOP

STEP 9: PTR → NEXT = TEMP → NEXT


STEP 10: TEMP → NEXT = PTR
STEP 11: SET PTR = NEW_NODE
STEP 12: EXIT

Prof. Kiran Shejul Dr. DYPIMED


IT - 12. Data Structure & Algorithms Unit 1: Array / List
Deletion:
The Deletion of a node from a singly linked list can be performed at different positions. Based
on the position of the node being deleted, the operation is categorized into the following
categories.

Deletion at Begining:

Deleting a node from the beginning of the list is the simplest operation of all. It just needs a
few adjustments in the node pointers. Since the first node of the list is to be deleted, therefore,
we just need to make the head, point to the next of the head. This will be done by using the
following statements.
ptr = head;
head = ptr->next;

Now, free the pointer ptr which was pointing to the head node of the list. This will be done by
using the following statement.
free(ptr)

Algorithm
Step 1: IF HEAD = NULL
Write UNDERFLOW
Go to Step 5
[END OF IF]
Step 2: SET PTR = HEAD
Step 3: SET HEAD = HEAD -> NEXT
Step 4: FREE PTR
Step 5: EXIT

Prof. Kiran Shejul Dr. DYPIMED


IT - 12. Data Structure & Algorithms Unit 1: Array / List
Deletion at End of List:
There are two scenarios in which, a node is deleted from the end of the linked list.

1. There is only one node in the list and that needs to be deleted.
2. There are more than one node in the list and the last node of the list will be
deleted.

In the first scenario,


the condition head → next = NULL will survive and therefore, the only node head of the list
will be assigned to null. This will be done by using the following statements.
ptr = head
head = NULL
free(ptr)
In the second scenario,
The condition head → next = NULL would fail and therefore, we have to traverse the node in
order to reach the last node of the list.

For this purpose, just declare a temporary pointer temp and assign it to head of the list. We also
need to keep track of the second last node of the list. For this purpose, two pointers ptr and ptr1
will be used where ptr will point to the last node and ptr1 will point to the second last node of
the list.
this all will be done by using the following statements.
ptr = head;
while(ptr->next != NULL)
{
ptr1 = ptr;
ptr = ptr ->next;
}
Now, we just need to make the pointer ptr1 point to the NULL and the last node of the list that
is pointed by ptr will become free. It will be done by using the following statements.
ptr1->next = NULL;
free(ptr);

Prof. Kiran Shejul Dr. DYPIMED


IT - 12. Data Structure & Algorithms Unit 1: Array / List

Algorithm
Step 1: IF HEAD = NULL
Write UNDERFLOW
Go to Step 8
[END OF IF]
Step 2: SET PTR = HEAD
Step 3: Repeat Steps 4 and 5 while PTR -> NEXT!= NULL
Step 4: SET PREPTR = PTR
Step 5: SET PTR = PTR -> NEXT
[END OF LOOP]
Step 6: SET PREPTR -> NEXT = NULL
Step 7: FREE PTR
Step 8: EXIT

Deletion after specified node :


It involves deleting the node after the specified node in the list. we need to skip the desired
number of nodes to reach the node after which the node will be deleted. This requires traversing
through the list.

Prof. Kiran Shejul Dr. DYPIMED


IT - 12. Data Structure & Algorithms Unit 1: Array / List

Algorithm
STEP 1: IF HEAD = NULL
WRITE UNDERFLOW
GOTO STEP 10
END OF IF
STEP 2: SET TEMP = HEAD
STEP 3: SET I = 0
STEP 4: REPEAT STEP 5 TO 8 UNTIL I
STEP 5: TEMP1 = TEMP
STEP 6: TEMP = TEMP → NEXT
STEP 7: IF TEMP = NULL
WRITE "DESIRED NODE NOT PRESENT"
GOTO STEP 12
END OF IF
STEP 8: I = I+1
END OF LOOP
STEP 9: TEMP1 → NEXT = TEMP → NEXT
STEP 10: FREE TEMP
STEP 11: EXIT

Prof. Kiran Shejul Dr. DYPIMED


IT - 12. Data Structure & Algorithms Unit 1: Array / List

Traversing in singly linked list


Traversing is the most common operation that is performed in almost every scenario of singly
linked list. Traversing means visiting each node of the list once in order to perform some
operation on that. This will be done by using the following statements.

ptr = head;
while (ptr!=NULL)
{
ptr = ptr -> next;
}

Algorithm
STEP 1: SET PTR = HEAD
STEP 2: IF PTR = NULL
WRITE "EMPTY LIST"
GOTO STEP 6
END OF IF

STEP 3: REPEAT STEP 4 AND 5 UNTIL PTR != NULL


STEP 4: PRINT PTR→ DATA
STEP 5: PTR = PTR → NEXT
[END OF LOOP]
STEP 6: EXIT

Prof. Kiran Shejul Dr. DYPIMED


IT - 12. Data Structure & Algorithms Unit 1: Array / List

Searching in singly linked list


Searching is performed in order to find the location of a particular element in the list. Searching
any element in the list needs traversing through the list and make the comparison of every
element of the list with the specified element. If the element is matched with any of the list
element then the location of the element is returned from the function.

Algorithm
Step 1: SET PTR = HEAD
Step 2: Set I = 0
STEP 3: IF PTR = NULL
WRITE "EMPTY LIST"
GOTO STEP 8
END OF IF

STEP 4: REPEAT STEP 5 TO 7 UNTIL PTR != NULL


STEP 5: if ptr → data = item
write i+1
End of IF

STEP 6: I = I + 1
STEP 7: PTR = PTR → NEXT
[END OF LOOP]

STEP 8: EXIT

Prof. Kiran Shejul Dr. DYPIMED


IT - 12. Data Structure & Algorithms Unit 1: Array / List
Doubly linked list

As the name suggests, the doubly linked list contains two pointers. We can define the doubly
linked list as a linear data structure with three parts: the data part and the other two address
part. In other words, a doubly linked list is a list that has three parts in a single node, includes
one data part, a pointer to its previous node, and a pointer to the next node.

Suppose we have three nodes, and the address of these nodes are 100, 200 and 300,
respectively. The representation of these nodes in a doubly-linked list is shown below:

As we can observe in the above figure, the node in a doubly-linked list has two address parts;
one part stores the address of the next while the other part of the node stores the previous
node's address. The initial node in the doubly linked list has the NULL value in the address
part, which provides the address of the previous node.

Insertion in doubly linked list at beginning


As in doubly linked list, each node of the list contains double pointers therefore we have to
maintain more number of pointers in doubly linked list as compare to singly linked list.
There are two scenarios of inserting any element into doubly linked list. Either the list is empty
or it contains at least one element.

Prof. Kiran Shejul Dr. DYPIMED


IT - 12. Data Structure & Algorithms Unit 1: Array / List
Algorithm :
Step 1: IF ptr = NULL
Write OVERFLOW
Go to Step 9
[END OF IF]
Step 2: SET NEW_NODE = ptr
Step 3: SET ptr = ptr -> NEXT
Step 4: SET NEW_NODE -> DATA = VAL
Step 5: SET NEW_NODE -> PREV = NULL
Step 6: SET NEW_NODE -> NEXT = START
Step 7: SET head -> PREV = NEW_NODE
Step 8: SET head = NEW_NODE
Step 9: EXIT

Insertion in doubly linked list at the end


In order to insert a node in doubly linked list at the end, we must make sure whether the list is
empty or it contains any element. Use the following steps in order to insert the node in doubly
linked list at the end.

Algorithm:
Step 1: IF PTR = NULL
Write OVERFLOW
Go to Step 11
[END OF IF]
Step 2: SET NEW_NODE = PTR
Step 3: SET PTR = PTR -> NEXT
Step 4: SET NEW_NODE -> DATA = VAL
Step 5: SET NEW_NODE -> NEXT = NULL
Step 6: SET TEMP = START
Step 7: Repeat Step 8 while TEMP -> NEXT != NULL
Step 8: SET TEMP = TEMP -> NEXT
[END OF LOOP]
Step 9: SET TEMP -> NEXT = NEW_NODE
Step 10C: SET NEW_NODE -> PREV = TEMP
Step 11: EXIT
Prof. Kiran Shejul Dr. DYPIMED
IT - 12. Data Structure & Algorithms Unit 1: Array / List
Insertion in doubly linked list after Specified node
In order to insert a node after the specified node in the list, we need to skip the required number
of nodes in order to reach the mentioned node and then make the pointer adjustments as
required.

Algorithm
Step 1: IF PTR = NULL
Write OVERFLOW
Go to Step 15
[END OF IF]
Step 2: SET NEW_NODE = PTR
Step 3: SET PTR = PTR -> NEXT
Step 4: SET NEW_NODE -> DATA = VAL
Step 5: SET TEMP = START
Step 6: SET I = 0
Step 7: REPEAT 8 to 10 until I
Step 8: SET TEMP = TEMP -> NEXT
STEP 9: IF TEMP = NULL
STEP 10: WRITE "LESS THAN DESIRED NO. OF ELEMENTS"
GOTO STEP 15
[END OF IF]
[END OF LOOP]
Step 11: SET NEW_NODE -> NEXT = TEMP -> NEXT
Step 12: SET NEW_NODE -> PREV = TEMP
Step 13 : SET TEMP -> NEXT = NEW_NODE
Step 14: SET TEMP -> NEXT -> PREV = NEW_NODE
Step 15: EXIT

Prof. Kiran Shejul Dr. DYPIMED


IT - 12. Data Structure & Algorithms Unit 1: Array / List
Deletion at beginning
Deletion in doubly linked list at the beginning is the simplest operation. We just need to copy
the head pointer to pointer ptr and shift the head pointer to its next.

Algorithm
STEP 1: IF HEAD = NULL
WRITE UNDERFLOW
GOTO STEP 6
STEP 2: SET PTR = HEAD
STEP 3: SET HEAD = HEAD → NEXT
STEP 4: SET HEAD → PREV = NULL
STEP 5: FREE PTR
STEP 6: EXIT

Prof. Kiran Shejul Dr. DYPIMED


IT - 12. Data Structure & Algorithms Unit 1: Array / List
Deletion in doubly linked list at the end
Deletion of the last node in a doubly linked list needs traversing the list in order to reach the
last node of the list and then make pointer adjustments at that position.

Step 1: IF HEAD = NULL


Write UNDERFLOW
Go to Step 7
[END OF IF]
Step 2: SET TEMP = HEAD
Step 3: REPEAT STEP 4 WHILE TEMP->NEXT != NULL
Step 4: SET TEMP = TEMP->NEXT
[END OF LOOP]
Step 5: SET TEMP ->PREV-> NEXT = NULL
Step 6: FREE TEMP
Step 7: EXIT

Prof. Kiran Shejul Dr. DYPIMED


IT - 12. Data Structure & Algorithms Unit 1: Array / List
Searching for a specific node in Doubly Linked List

We just need traverse the list in order to search for a specific element in the list. Perform
following operations in order to search a specific operation.

• Copy head pointer into a temporary pointer variable ptr.


ptr = head
• declare a local variable I and assign it to 0.
i=0

• Traverse the list until the pointer ptr becomes null. Keep shifting pointer to its next and
increasing i 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.

Algorithm
Step 1: IF HEAD == NULL
WRITE "UNDERFLOW"
GOTO STEP 8
[END OF IF]
Step 2: Set PTR = HEAD
Step 3: Set i = 0
Step 4: Repeat step 5 to 7 while PTR != NULL
Step 5: IF PTR → data = item
return i
[END OF IF]
Step 6: i = i + 1
Step 7: PTR = PTR → next
Step 8: Exit

Prof. Kiran Shejul Dr. DYPIMED


IT - 12. Data Structure & Algorithms Unit 1: Array / List
Traversing in doubly linked list
Traversing is the most common operation in case of each data structure. For this purpose, copy
the head pointer in any of the temporary pointer ptr.
Ptr = head

then, traverse through the list by using while loop. Keep shifting value of pointer variable ptr
until we find the last node. The last node contains null in its next part.

while(ptr != NULL)
{
printf("%d\n",ptr->data);
ptr=ptr->next;
}
Although, traversing means visiting each node of the list once to perform some specific
operation. Here, we are printing the data associated with each node of the list.

Algorithm
Step 1: IF HEAD == NULL
WRITE "UNDERFLOW"
GOTO STEP 6
[END OF IF]
Step 2: Set PTR = HEAD
Step 3: Repeat step 4 and 5 while PTR != NULL
Step 4: Write PTR → data
Step 5: PTR = PTR → next
Step 6: Exit

Prof. Kiran Shejul Dr. DYPIMED


IT - 12. Data Structure & Algorithms Unit 1: Array / List
➢ 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.

The following image shows a circular linked list.

Circular linked list is mostly used in task maintenance in operating systems. There are many
examples where circular linked list is being used in computer science including browser surfing
where a record of pages visited in the past by the user, is maintained in the form of circular
linked lists and can be accessed again on clicking the previous button.

Types of Circular Linked Lists


We can create a circular linked list from both singly linked lists and doubly linked lists. So,
circular linked list are basically of two types:

1. Circular Singly Linked List


In Circular Singly Linked List, each node has just one pointer called the “next” pointer. The
next pointer of last node points back to the first node and this results in forming a circle. In this
type of Linked list we can only move through the list in one direction.

Prof. Kiran Shejul Dr. DYPIMED


IT - 12. Data Structure & Algorithms Unit 1: Array / List

2. Circular Doubly Linked List:

In circular doubly linked list, each node has two pointers prev and next, similar to doubly linked
list. The prev pointer points to the previous node and the next points to the next node. Here, in
addition to the last node storing the address of the first node, the first node will also store the
address of the last node.

Prof. Kiran Shejul Dr. DYPIMED

You might also like