Given a circular singly linked list containing N nodes. The task is to delete all nodes from the list which are prime.
Input : 9->11->32->6->13->20 Output : Given List : 9 11 32 6 13 20 List After delete prime node : 9 32 6 20 Input : 6->11->16->21->17->10 Output : Given List : 6 11 16 21 17 10 List After delete prime node : 10 21 16 6
Approach: The idea is to traverse the nodes of the circular singly linked list one by one and get the pointer of the nodes which are prime. Delete those nodes by following the approach used in the post: Delete a node from circular Linked List.
Below is the implementation of the above idea:
Given List : 9 11 32 6 13 20 List After deleting prime nodes : 9 32 6 20
- Delete all Prime Nodes from a Singly Linked List
- Delete all Non-Prime Nodes from a Singly Linked List
- Sum and Product of the nodes of a Circular Singly Linked List which are divisible by K
- Delete all the even nodes of a Circular Linked List
- Delete all odd or even positioned nodes from Circular Linked List
- Sum and Product of all Prime Nodes of a Singly Linked List
- Count of Prime Nodes of a Singly Linked List
- Delete all Prime Nodes from a Doubly Linked List
- Circular Singly Linked List | Insertion
- Convert singly linked list into circular linked list
- Given only a pointer to a node to be deleted in a singly linked list, how do you delete it?
- Sum of the nodes of a Singly Linked List
- Given only a pointer/reference to a node to be deleted in a singly linked list, how do you delete it?
- Find minimum and maximum elements in singly Circular Linked List
- Delete every Kth node from circular linked list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.