2. Content-:
• Circular linked list
• Difference b/w linear linked list and circular
linked list
• Types of circular linked list
• Advantages
• Disadvantages
• Operations based on both the types
4. What is circular linked list?
• Circular linked list is a variation of linked list in
which the first elements points to the next
element and the last element points to the first
element.
• Both singly and doubly linked list can be made
into a circular linked list.
• Circular linked list can be used to help traverse
the same list again and again if needed.
5. Fun fact:
If you are worried about its implementation, then stop
doing that because instead of placing NULL at the last
node’s address field you are placing the address of very
first node!
6. Circular linked list vs. Linear linked list
• A circularly linked list may be a natural option to represent arrays
that are naturally circular, e.g. the corners of a polygon, a pool
of buffers that are used and released in FIFO order, or a set of
processes that should be time-shared. In these applications, a pointer
to any node serves as a handle to the whole list.
• With a circular list, a pointer to the last node gives easy access also to
the first node, by following one link. Thus, in applications that
require access to both ends of the list, a circular structure allows one
to handle the structure by a single pointer, instead of two.
• The simplest representation for an empty circular list (when such a
thing makes sense) is a null pointer, indicating that the list has no
nodes. Without this choice, many algorithms have to test for this
special case, and handle it separately. By contrast, the use of null to
denote an empty linear list is more natural and often creates fewer
special cases.
7. Types of circular linked list:
1. Singly: The last node points to the first node and there is only
link between the nodes of linked list.
2. Doubly: The last node points to the first node and there are two
links between the nodes of linked list.
8. Advantages of Circular linked lists:
1. Any node can be a starting point. We can traverse the whole
list by starting from any point. We just need to stop when
the first visited node is visited again.
2. Circular lists are useful in applications to repeatedly go
around the list. For example: when multiple applications
are running on a PC, it is common for the operating system
to put the running applications on a list and then to cycle
through them, giving each of them a slice of time to execute,
and then making them wait while the CPU is given to
another application. It is convenient for the operating
system to use a circular list so that when it reaches the end
of the list it can cycle around to the front of the list.
3. Circular Doubly Linked Lists are used for implementation
of advanced data structures like Fibonacci Heap.
9. Disadvantages of Circular linked list
1. Depending on the implementation, inserting at
start of list would require doing a search for
last node which could be expensive.
2. Finding end of the list and loop control is
harder ( no NULL’s to mark the beginning and
end).
11. Insertion :
• Insertion can be of three types.
▫ Insert at first
▫ Insert at last
▫ Insert after constant
• Note: insertion after constant in circular and
linear linked list is exact same .
13. Algorithm Program
Void addfront()
{
struct node *t=start;
struct node *n=(struct
node*)malloc(sizeof(struct
node));
printf(“nenter the
information”);
scanf(“%d”,&n->info);
• Start.
• Declare struct node *t.
• Set t:=start.
• Create a new node n
by malloc function and
enter the information
in info part.
• Check if start=NULL
set start=n
set start->next=start.
else
• Set n->next=start.
16. Algorithm Program
Void addlast()
{
struct node *t=start;
• Start.
• Declare struct node *t.
• Set t:=start.
• Create a new node n
by malloc function and
enter the information
in info part.
• Check if start=NULL
then,
set start:=n.
set start->next:=start.
Otherwise
• Set n->next:=start.
struct node *n=(struct
node*)malloc(sizeof(struct
node));
printf(“nenter the
information”);
scanf(“%d”,&n->info);
18. Deletion :
• Deletion can be of three types.
▫ Delete from front
▫ Delete from last
▫ Deletion from mid
• Note: deletion from mid in circular and linear
linked list is exact same .