# Delete all the even nodes of a Circular Linked List

Assume that given linked list are exist integer node value, and we are removing all nodes of this Circular linked list which are contains the values of Even key values.

Suppose we are inserted the following (12, 21, 30, 41, 53, 60, 79, 88) node in a sequence.

Before solve this problem consider following test cases.

1) When no element of linked list then display proper message like Empty linked list.

2) When only one element of linked list and this node value are even data. then delete this node and set to head pointer of linked list is NULL.

3) When head node of linked list value is even data. so linked list last node is assigned to new upcoming head node. that means when deleting any of node there are always satisfied the properties of circular linked list.

4) When intermediate node are linked list is Even value node. In this case modified the link of previous nodes next pointer value to upcoming next node.

loop termination condition is important factor of this problem. because linked list are circular so terminate condition is main factor. so terminate loop when next upcoming node are already iterates.

Here given code implementation process.

``````//C Program
//Delete Even key nodes of Circular Linked List
#include <stdio.h>
#include <stdlib.h> //for malloc function

//Create structure
struct Node{
int data;
struct Node*next;
};
//function prototype
void insert(struct Node**,int);
void display(struct Node*);
//insert Node element at end of linked list
//Create dynamic node
struct Node*node=(struct Node*)malloc(sizeof(struct Node));
if(node==NULL){
printf("Memory overflow\n");
}else{
node->data=value;
}else{
temp=temp->next;
}
temp->next=node;
}
}
}
//Display element of Node

}
else{
while(temp){
printf("  %d",temp->data);
temp=temp->next;
break; //terminate loop
}
}

}
}

*prev=NULL,
*hold=NULL,
*modifier=NULL;

if(temp->data%2==0){
//even node
hold=temp;
}else{
prev=temp;
}
temp=temp->next;

if(hold!=NULL){
//delete node found
if(modifier==NULL){
modifier=hold->next;
if(modifier!=NULL){
//find last node and change last node
//next pointer
modifier=modifier->next;
}
}
else{
//single element
}

}
}else{
}

}
if(prev!=NULL){
//delete intermediates nodes
prev->next=hold->next;
temp=NULL; //no other element
}
}
hold->next=NULL;
free(hold);
hold=NULL;
}

}
}else{
}
}
int main(){
//create node pointer

printf("\n Before Delete Even Nodes");
//display all node
printf("\n After Delete Even Nodes");
return 0;
}``````

#### Output

`````` Before Delete Even Nodes
Linked List Element :  12  21  30  41  53  60  79  88
After Delete Even Nodes
Linked List Element :  21  41  53  79``````
``````//C++ Program
//Delete Even key nodes of Circular Linked List
#include<iostream>
using namespace std;

//create structure
struct Node{
int data;
struct Node*next;
};
class CircularList{
public:
CircularList();
void insert(int);
void display();
void del_even();
};
CircularList::CircularList(){
}

//insert Node at end of linked list
void CircularList::insert(int value){
//Create dynamic node
struct Node*node=new Node;
if(node==NULL){
cout<<"Memory overflow"<<endl;
}else{
node->data=value;
}else{
//find last node
temp=temp->next;
}
temp->next=node;
}
}
}
//display element of Node
void CircularList:: display(){

}
else{
while(temp){
cout<<"  "<<temp->data;
temp=temp->next;
break; //terminate loop
}
}

}
}
void CircularList:: del_even(){

*prev=NULL,
*hold=NULL,
*modifier=NULL;

if(temp->data%2==0){
//even node
hold=temp;
}else{
prev=temp;
}
temp=temp->next;

if(hold!=NULL){
//delete node found
if(modifier==NULL){
modifier=hold->next;
if(modifier!=NULL){
//find last node and change last node
//next pointer
modifier=modifier->next;
}
}
else{
//single element
}

}
}else{
}

}
if(prev!=NULL){
//delete intermediates nodes
prev->next=hold->next;
temp=NULL; //no other element
}
}
hold->next=NULL;
delete hold;
hold=NULL;
}

}
}else{
}
}
int main(){
CircularList obj=CircularList();
obj.insert(12);
obj.insert(21);
obj.insert(30);
obj.insert(41);
obj.insert(53);
obj.insert(60);
obj.insert(79);
obj.insert(88);
cout<<"Before Delete Even Nodes"<<endl;
//display all node
obj.display();
cout<<"\nAfter Delete Even Nodes"<<endl;
obj.del_even();
//display all node
obj.display();
}``````

#### Output

``````Before Delete Even Nodes
Element of linked list :  12  21  30  41  53  60  79  88
After Delete Even Nodes
Element of linked list :  21  41  53  79``````
``````//Java Program to
//Delete Even key nodes of Circular Linked List
static class Node{
int data;
Node next;
}
//Class constructors
}
//insert node at last of linke list
static void insert(int value){
//Create a node
Node node=new Node();
node.data=value;
}
else{
//find lase node
temp=temp.next;
}
temp.next=node;
}

}
//Display node element of circular linked list
static void display(){
}else{
while(temp!=null){
System.out.print("  "+temp.data);
temp=temp.next;
}
}
}
static void deleteEven(){

prev=null,
hold=null,
modifier=null;

if(temp.data%2==0){
//even node
hold=temp;
}else{
prev=temp;
}
temp=temp.next;

if(hold!=null){
//delete node found
if(modifier==null){
modifier=hold.next;
if(modifier!=null){
//find last node and change last node
//next pointer
modifier=modifier.next;
}
}
else{
//single element
}

}
}else{
}

}
if(prev!=null){
//delete intermediates nodes
prev.next=hold.next;
temp=null; //no other element
}
}
hold.next=null;
hold=null;
}

}
}else{
}
}

public static void main(String[] args) {
obj.insert(12);
obj.insert(21);
obj.insert(30);
obj.insert(41);
obj.insert(53);
obj.insert(60);
obj.insert(79);
obj.insert(88);
System.out.println("Before Delete Even Nodes");
//display all node
obj.display();
System.out.println("\nAfter Delete Even Nodes");
obj. deleteEven();
//display all node
obj.display();

}
}``````

#### Output

``````Before Delete Even Nodes
Circular Linked List Element :  12  21  30  41  53  60  79  88
After Delete Even Nodes
Circular Linked List Element :  21  41  53  79``````
``````#Python Insert  linked list node at
#Delete Even key nodes of Circular Linked List
class Node:
def __init__(self,data):
self.data=data
self.next=None

#create class CircularList
class CircularList:
def __init__(self):
#Assign default value

#Insert new node to End of Linked list
def insert(self,data):
node=Node(data)
#when no element of linked list
node.next=node
else:
temp=temp.next
temp.next=node
#display all element of circular linked list
def display(self):
while(temp!=None):
print(temp.data),
temp=temp.next
#when find first node
print("\n")
break

def deleteEven(self):

else:
prev=None
hold=None
modifier=None
if(temp.data%2==0):
#even node
hold=temp
else:
prev=temp

temp=temp.next

temp=None
if(hold!=None):

if(modifier==None):

modifier=hold.next

if(modifier!=None):

modifier=modifier.next

else:
#single element

else:
if(prev!=None):
#delete intermediates nodes
prev.next=hold.next
temp=None #no other element

hold.next=None
hold=None

def main():
#Create Object of class CircularList
obj=CircularList()
#Insert element
obj.insert(12)
obj.insert(21)
obj.insert(30)
obj.insert(41)
obj.insert(53)
obj.insert(60)
obj.insert(79)
obj.insert(88)
print("Before Delete Even Nodes")
#display all node
obj.display()
print("After Delete Even Nodes")
obj.deleteEven()
#display all node
obj.display()
if __name__ == '__main__':
main()``````

#### Output

``````Before Delete Even Nodes
Linked list Elements :  12 21 30 41 53 60 79 88

After Delete Even Nodes
Linked list Elements :  21 41 53 79

``````
``````//C# program to
//Delete Even key nodes of Circular Linked List
using System;
//node class
public class Node{
public  int data;
public  Node next;
}
class Program
{
public Program(){
}
public void insert(int data){
Node newNode=new Node();
newNode.data=data;
//when no element of linked list
}
else{
//get last node
temp=temp.next;
}
temp.next=newNode;
}
}
public void display(){
}else{
while(temp!=null){
Console.Write(" {0}",temp.data);
temp=temp.next;
//End of Loop iteration
}
}
}
public void deleteEven(){

prev=null,
hold=null,
modifier=null;

if(temp.data%2==0){
//even node
hold=temp;
}else{
prev=temp;
}
temp=temp.next;

if(hold!=null){
//delete node found
if(modifier==null){
modifier=hold.next;
if(modifier!=null){
//find last node and change last node
//next pointer
modifier=modifier.next;
}
}
else{
//single element
}

}
}else{
}

}
if(prev!=null){
//delete intermediates nodes
prev.next=hold.next;
temp=null; //no other element
}
}
hold.next=null;
hold=null;
}

}
}else{
}
}

static void Main(){

Program obj=new Program();
obj.insert(12);
obj.insert(21);
obj.insert(30);
obj.insert(41);
obj.insert(53);
obj.insert(60);
obj.insert(79);
obj.insert(88);
Console.Write("Before Delete Even Nodes");
//display all node
obj.display();
Console.Write("\nAfter Delete Even Nodes");
obj. deleteEven();
//display all node
obj.display();
}
}``````

#### Output

``````Before Delete Even Nodes
Circular Linked List :  12 21 30 41 53 60 79 88
After Delete Even Nodes
Circular Linked List :  21 41 53 79``````

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.