Page 554 - Computer science 868 Class 12
P. 554
12. (a) The class structure of the Node is given below: [ISC 2019]
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)
Ans. void sumEvenNode(Node str) {
if(str == null)
return 0;
else if(str.num % 2 == 0)
return str.num + sumEvenNode(str.next);
else
return 0 + sumEvenNode(str.next);
(b) Answer the following questions from the diagram of a Binary Tree given below: [ISC 2019]
A
E B
G C D
I H F
(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
Ans. (I) Pre-order traversal: A → E → G → I → C → H → B → D → F
(ii) The size of the tree is 4.
(iii) Sibling of E is B. Sibling of G is C.
13. A linear data structure enables the user to add an address from rear end and remove address from front. Define a class Diary
with the following details :
Class name : Diary
Data Members/Instance variables
Q[] : array to store the addresses
size : stores the maximum capacity of the array
start : to point the index of the front end
end : to point the index of the rear end
Member Functions
Diary(int max) : constructor to initialise the data member size = max, start=0 and end=0
void pushadd(String n) : to add the address in the diary from the rear end if possible, otherwise display
the message “NO SPACE”
String popadd() : removes and returns the address from the front end of the diary if any, else
returns “?????”
void show () : displays all the addresses in the diary
(a) Specify the class Diary giving details of the functions void pushadd(String) and String popadd(). Assume that the other
functions have been defined.
The main function and algorithm need NOT be written.
552552 Touchpad Computer Science-XII

