Given a circular singly linked list containing N nodes, the task is to delete all the even nodes from the list.

**Examples:**

Input :57->11->2->56->12->61Output :List after deletion : 57 -> 11 -> 61Input :9->11->32->6->13->20Output :List after deletion : 9 -> 11 -> 13

The idea is to traverse the nodes of the circular singly linked list one by one and get the pointer of the nodes having even data. Delete those nodes by following the approach used in this post.

Below is the implementation of the above idea:

`// CPP program to delete all even ` `// node from a Circular singly linked list ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Structure for a node ` `struct` `Node { ` ` ` `int` `data; ` ` ` `struct` `Node* next; ` `}; ` ` ` `// Function to insert a node at the begining ` `// of a Circular linked list ` `void` `push(` `struct` `Node** head_ref, ` `int` `data) ` `{ ` ` ` `struct` `Node* ptr1 = (` `struct` `Node*)` `malloc` `(` `sizeof` `(` `struct` `Node)); ` ` ` `struct` `Node* temp = *head_ref; ` ` ` `ptr1->data = data; ` ` ` `ptr1->next = *head_ref; ` ` ` ` ` `// If linked list is not NULL then ` ` ` `// set the next of last node ` ` ` `if` `(*head_ref != NULL) { ` ` ` `while` `(temp->next != *head_ref) ` ` ` `temp = temp->next; ` ` ` `temp->next = ptr1; ` ` ` `} ` ` ` `else` ` ` `ptr1->next = ptr1; ` `// For the first node ` ` ` ` ` `*head_ref = ptr1; ` `} ` ` ` `// Delete the node if it is even ` `void` `deleteNode(Node* head_ref, Node* del) ` `{ ` ` ` `struct` `Node* temp = head_ref; ` ` ` `// If node to be deleted is head node ` ` ` ` ` `if` `(head_ref == del) ` ` ` `head_ref = del->next; ` ` ` ` ` `// travers list till not found ` ` ` `// delete node ` ` ` `while` `(temp->next != del) { ` ` ` `temp = temp->next; ` ` ` `} ` ` ` ` ` `// copy address of node ` ` ` `temp->next = del->next; ` ` ` ` ` `// Finally, free the memory occupied by del ` ` ` `free` `(del); ` ` ` `return` `; ` `} ` ` ` `// Function to delete all even nodes ` `// from the singly circular linked list ` `void` `deleteEvenNodes(Node* head) ` `{ ` ` ` `struct` `Node* ptr = head; ` ` ` ` ` `struct` `Node* next; ` ` ` ` ` `// traverse list till the end ` ` ` `// if the node is even then delete it ` ` ` `do` `{ ` ` ` `// if node is even ` ` ` `if` `(ptr->data % 2 == 0) ` ` ` `deleteNode(head, ptr); ` ` ` ` ` `// point to next node ` ` ` `next = ptr->next; ` ` ` `ptr = next; ` ` ` `} ` `while` `(ptr != head); ` `} ` ` ` `// Function to print nodes ` `void` `printList(` `struct` `Node* head) ` `{ ` ` ` `struct` `Node* temp = head; ` ` ` `if` `(head != NULL) { ` ` ` `do` `{ ` ` ` `printf` `(` `"%d "` `, temp->data); ` ` ` `temp = temp->next; ` ` ` `} ` `while` `(temp != head); ` ` ` `} ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `// Initialize lists as empty ` ` ` `struct` `Node* head = NULL; ` ` ` ` ` `// Created linked list will be 57->11->2->56->12->61 ` ` ` `push(&head, 61); ` ` ` `push(&head, 12); ` ` ` `push(&head, 56); ` ` ` `push(&head, 2); ` ` ` `push(&head, 11); ` ` ` `push(&head, 57); ` ` ` ` ` `cout << ` `"\nList after deletion : "` `; ` ` ` `deleteEvenNodes(head); ` ` ` `printList(head); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

**Output:**

List after deletion : 57 11 61

**Time Complexity: O(N)**, where N is the total number of nodes.

## Recommended Posts:

- Delete all odd or even positioned nodes from Circular Linked List
- Delete all Prime Nodes from a Circular Singly Linked List
- Delete every Kth node from circular linked list
- Delete N nodes after M nodes of a linked list
- Sum of the nodes of a Circular Linked List
- Delete alternate nodes of a Linked List
- Delete all the even nodes from a Doubly Linked List
- Exchange first and last nodes in Circular Linked List
- Count nodes in Circular linked list
- Delete all nodes from the doubly linked list which are divisible by K
- Delete all Prime Nodes from a Doubly Linked List
- Delete all Non-Prime Nodes from a Singly Linked List
- Delete all the nodes from the doubly linked list that are greater than a given value
- Delete all the nodes from a doubly linked list that are smaller than a given value
- Delete all Prime Nodes from a Singly 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 contribute@geeksforgeeks.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.