Question
A linked list is formed from the objects of the class Node. The class structure of the
Node is given below:
class Node
{
int num;
Node next;
}
Write an Algorithm OR a Method to find and display the sum of even integers from an existing linked list.
The method declaration is as follows:
void SumEvenNode( Node str )
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
void SumEvenNode(Node str)
{
Node temp=str;
int s=0;
while(temp!=null )
{
if (temp.num%2==0)
{
s=s+temp.num;
}
temp=temp.next;
}
System.out.println("sum of even integers="+s);
}