- 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)
void sumEvenNode(Node str){ int sum = 0; if(str == null) System.out.println("Sum = 0"); else{ while(str != null){ if(str.num % 2 == 0) sum += str.num; str = str.next; } System.out.println("Sum = " + sum); }
- Answer the following questions from the diagram of a binary tree given below:
- Write the pre-order traversal of the above tree structure.
A –> E –> G –> I –> C –> H –> B –> D –> F - State the size of the tree.
The size of the tree is 4. - Name the siblings of the nodes E and G.
Sibling of E is B.
Sibling of G is C.