Lecture # 5 Circular Link List
Lecture # 5 Circular Link List
Lecture-5
University of Sialkot
Problems with Linked Lists
-3 4 -1 NULL
header
A node in the list
header
2 -3 4 -1
header
Have the last node link back to the first (or the header).
Circular Linked Lists
• Circular linked lists avoid the use of null
references in their nodes
• Can be useful for certain algorithms
• Can also make programming simpler: fewer
special cases to consider
• Successor of tail node is the head node; in
doubly-linked list
Circular linked lists
• Insertions and deletions into a circular linked
list follow the same logic patterns used in a
singly linked list except that the last node
points to the first node.
Circular linked list
• Advantage is that we can start searching from any
node of the linked list and get to any other node.
}
}
Main function
int main()
{
Node * head = Null ;
Insertattail(1);
Insertattail(2);
Insertattail(3);
Display();
Insertathead(4);
Display();
}
Deletion
Void deletion(int position)
{ While(current!=pos-1);
If (pos==1) {
{ Temp = temp->next;
Deleteathead(); current++;
Return; }
}
Node *todelete = temp->next;
Temp->next= temp->next->next;
node *temp = head; delete todelete;
int current = 1 ; }
Delete At head
Void deleteathead() Node * todelete = head ;
{
Node *temp = head; temp->next = head->next ;
While(temp->next !
Head = head-> next;
=head)
{ Delete todelete;
Temp = temp->next;
} }
THANKS