a) 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 )
b) Answer the following questions from the diagram of a Binary Tree given below
(i) Write the pre-order traversal of the above tree structure
(ii) State the size of the tree.
(iii)Name the siblings of the nodes E and G
a) ALGORITHM:
Step 1. Start
Step 2. Set temporary pointer to the first node
Step 3. Repeat steps 4 and 5 until the pointer reaches null. Display sum, exit
Step 4. check for even number, if found accumulate
Step 5. Move pointer to the next node
Step 6. End algorithm
METHOD:
void SumEvenNode(Node str)
{
Node temp=new Node(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);
}
(b)
(i)
A E G I C H B D F
(ii)
9
(iii)
SIBLING OF E IS B
SIBLING OF G IS C