April 2000 QUESTION 3 Total Marks: 15 Marks |
Click here to access other
questions
SUGGESTED SOLUTIONS |
Do not award half marks. Do not deduct marks for trivial syntactic rors. Alternative correct answers should be given credit, unless otherwise indicated in the marking scheme. You are to implement a stack which can
be used for job control.When a job is created by the system,a stack
element is created which is used to store the details of the job.Jobs
are always added to and removed from the top of the stack,thereby
making it a first in last out data structure,and each element added
to the stack also contains a ointer which is used to point to the
next element down the stack. (a)Define a suitable enumerated type,called
JobType which can take on any of the values SystemJob ClientJob or
ServerJob [1mark ] (b)Give a definition of the structure
Job which contains the members type which is a JobType and data which
is a pointer with an undefined type.[3 marks ] (c)Define a function,IsEmpty the signature
of which is given below,which takes a stack s and returns 1 if the
stack is empty,and zero otherwise.A stack is defined to be empty if
there are no elements on the stack. (d)Define a procedure Push the signature
of which is given below,which takes a reference to a stack s and a
reference to a stack element e and will add the element to the top
of the stack.Your procedure should ensure that both the stack pointer
and the reference to the next item in the stack are updated,should
it be necessary. (e)Define a procedure Pop the signature
of which is given below,which takes a reference to a stack s anda
stack element e The procedure should remove the to element from the
stack,returning a reference to the element removed,and should return
the number of items successfully removed from the stack. |