Professional Documents
Culture Documents
ANSWER SCHEME
INSTRUCTIONS TO CANDIDATES
2. Answer ALL questions in the Answer Booklet. Start each answer on a new page.
3. Do not bring any material into the examination room unless permission is given by the
invigilator.
a) What is the different between singly, doubly and circular linked list?
(6 marks)
Assume TEN (10) printer object have been inserted into a Queue named PrinterQueue.
i) Write a program segment that will get the data from PrinterQueue based on their
brand and store into TWO (2) different LinkedList named CanonList and
BrotherList
(5 marks)
Printer p=PrinterQueue.dequeue();
if (p.getBrand().equals.IgnoreCase(“Canon”))
CanonList.insertAtBack(p);
else
BrotherList.insertAtBack(p);
ii) Calculate and display the total price of the printer from CanonList.
(4 marks)
float totalprice=0.0;
Object obj=CanonList.getFirst();
while (obj != null)
{
Printer p=(Printer)obj;
totalprice += p.getPrice();
obj=CanonList.getNext();
}
iii) Store all the laser type printer from BrotherList with the price of more than
RM1000 into a stack named expensivePrinter.
(4 marks)
iv) Write the method public void enqueue(Object data){…}. Hints: The queue
extends the LinkedList class.
(3 marks)
v) Write the method public Object pop(){…}. Hints: The stack extends the
LinkedList class.
(3 marks)
public Object pop()
{
return removeAtFront();
}
QUESTION 3 (6 marks)
(3 marks)
(3 marks)
QUESTION 4 ( 15 marks)
a) The recursive definition below is the formula to find n-th power of ten:
Func(n) = 1 if n = 0
(4 marks)
(6 marks)
public static int Calc(int n)…………………….2
{
if (n==0) return 0;…………………………..1.5
else…………….0.5