‹ Back to the paper
Recycle is an entity which can hold at the most 100 integers. The chain enables the user to add and…
Recycle is an entity which can hold at the most 100 integers. The chain enables the user to add and remove integers from both the ends i.e. front and rear.
Define a class ReCycle with the following details:
Class name : ReCycle
Data members/instance variables:
ele[ ] : the array to hold the integer elements
cap : stores the maximum capacity of the array
front : to point the index of the front
rear : to point the index of the rear
Methods / Member functions:
ReCycle (int max) : constructor to initialize the data cap = max, front = rear = 0 and to create the integer array.
void pushfront(int v) : to add integers from the front index if possible else display the message(“full from front”).
int popfront( ) : to remove the return elements from front. If array is empty then return-999.
void pushrear(int v) : to add integers from the front index if possible else display the message(“full from rear”).
int poprear( ) : to remove and return elements from rear. If the array is empty then return-999.
(i)[4.0]
Specify the class ReCycle giving details of the functions void pushfront(int) and int poprear( ). Assume that the other functions have been defined. The main( ) function and algorithm need NOT be written.
(ii)[1.0]
Name the entity described above and state its principle.
Answer
Answer (i)
Official answer keyvoid pushfront(int v)
{
if (front != 0)
ele[front--] = v;
else
System.out.println("full from front");
}
int poprear()
{
if (front != rear)
return ele[rear--];
else
return -999;
}Explanation: This follows the same indexing scheme used by the already-defined pushrear()/popfront() methods of ReCycle. pushfront() stores the new value at the current front index and then decrements front (so ele[] fills from the front end downward), printing "full from front" if front has already reached 0 (no more room at that end). poprear() removes and returns the element at the current rear index and then decrements rear, unless front and rear have met (the structure is empty), in which case it returns -999.Answer (ii)
Official answer keyThe entity described is a Deque (Double Ended Queue). It works on a generalisation of the FIFO principle to both ends: insertion and deletion of elements are allowed from both the front and the rear of the structure, unlike a simple queue which allows insertion only at the rear and deletion only at the front.
From ISC 2025 Specimen Computer Science Paper 1, question 9.