Page 555 - Computer science 868 Class 12
P. 555
Ans. class Diary {
public void pushAdd(String n) {
if(Q[0].equals(""))
Q[0] = n;
else if(end + 1 < size) Q[end + 1] = n;
else
System.out.println("NO SPACE");
}
public String popadd() {
if(start -1 >= 0)
return Q[start--];
else
return "?????";
}
}
(b) Name the entity used in the above data structure arrangement. [ISC 2019]
Ans. Queue
14. Convert the following infix notation to postfix form: [ISC 2018]
A + (B – C*(D/E) * F)
Ans. A + (B – C * (D / E) * F)
= A + (B – C * DE/ * F)
= A + (B- CDE/* * F)
=A + (BCDE/*F*-)
ABCDE/*F*-+
15. Register is an entity which can hold a maximum of 100 names. The register enables the user to add and remove names from
the top most end only. [ISC 2018]
Define a class Register with the following details:
Class name : Register
Data Members/Instance variables
stud[ ] : array to store the names of the students cap stores the maximum capacity of
the array top to point the index of the top end
Member Functions
Register (int max) : constructor to initialise the data member cap = max, top = −1 and create the
string array
void push(String n) : to add names in the register at the top location if possible, otherwise display
the message “OVERFLOW”
String pop() : removes and returns the names from the top most location of the register if
any, else returns “$$”
void display() : displays all the names in the register
(a) Specify the class Register giving details of the functions void push(String) and String pop( ). Assume that the other functions
have been defined. The main function and algorithm need NOT be written.
Ans. class Register
{
void push(String n)
{
if (top<cap-1)
stud[++top]=n;
else
System.out.println("OVERFLOW");
}
String pop()
553
Data Structures 553

