Professional Documents
Culture Documents
CSC508 Test 1 - Set 2
CSC508 Test 1 - Set 2
CSC508 Test 1 - Set 2
INSTRUCTION TO CANDIDATES
1. This question paper consists of four (3) questions.
2. Answer ALL questions in your answer sheet. Start each answer on a new page. Write your
name, id and group on the answer sheet.
3. Please scan and save your answers as ONE pdf file.
4. No discussion and do not share your answers with other students. Any copying of or
plagiarized answers will be awarded 0 mark.
5. Answer ALL questions in English.
class patient{
String ID;
String name;
int age;
patient link;
}
class clinicQueue{
//Attribute 1
//Attribute 2
//Attribute 3
clinicQueue() {...}
//constructor, initialize the queue
The above program is use define a queue management system (QMS) in a clinic, based on
linked list. The class patient is defines the node, and clinicQueue defines linked list.
(a) Declare the three attributes for class clinicQueue, the efficiency enqueue() and
waiting() is O(1).
(3 marks)
(c) The clinic management wanted to give priority for patients aged 60 years and above,
where they can skip three patients younger than them at the end of the queue. Define the
method enqueue(), with appropriate parameters, to suit this rule.
(6 marks)
QUESTION 3 (8 marks)
import java.util.Scanner;
class stack {
int []arrStack;
int top;
public stack(){
arrStack = new int[10];
top = -1;}
if (match.isEmpty())
System.out.println("MATCHED");
else
System.out.println("NOT MATCHED");
}
}
The above program is intended to check for parenthesis matching.
(a) Trace the output of the program when the input (a(bc)d)efg(h))is entered.
(4 marks)
(b) Based on your finding in (a), suggest an update to improve the program.
(4 marks)