import
java.util.*;
class
GFG{
static
class
Node
{
int
data;
Node prev, next;
};
static
Node push(Node head_ref,
int
new_data)
{
Node new_node =
new
Node();
new_node.data = new_data;
new_node.prev =
null
;
new_node.next = head_ref;
if
(head_ref !=
null
)
head_ref.prev = new_node;
head_ref = new_node;
return
head_ref;
}
static
int
digitSum(
int
num)
{
int
sum =
0
;
while
(num >
0
)
{
sum += (num %
10
);
num /=
10
;
}
return
sum;
}
static
Node deleteNode(Node head_ref,
Node del)
{
if
(head_ref ==
null
||
del ==
null
)
return
head_ref;
if
(head_ref == del)
head_ref = del.next;
if
(del.next !=
null
)
del.next.prev = del.prev;
if
(del.prev !=
null
)
del.prev.next = del.next;
del =
null
;
return
head_ref;
}
static
Node deleteEvenDigitSumNodes(Node head_ref)
{
Node ptr = head_ref;
Node next;
while
(ptr !=
null
)
{
next = ptr.next;
if
(!(digitSum(ptr.data) %
2
==
1
))
head_ref = deleteNode(head_ref, ptr);
ptr = next;
}
return
head_ref;
}
static
void
printList(Node head)
{
while
(head !=
null
)
{
System.out.print(head.data +
" "
);
head = head.next;
}
}
public
static
void
main(String[] args)
{
Node head =
null
;
head = push(head,
14
);
head = push(head,
9
);
head = push(head,
8
);
head = push(head,
15
);
head = push(head,
18
);
System.out.print(
"Original List: "
);
printList(head);
head = deleteEvenDigitSumNodes(head);
System.out.print(
"\nModified List: "
);
printList(head);
}
}