December 1999
CA208 : 'C' PROGRAMMING

QUESTION 2

Total Marks: 15 Marks

Click here to access other questions

Click to access
SUGGESTED SOLUTIONS
for Question 2

You are to implement a task queueing system.When a task is entered into the system,it has assigned to it a priority,which is one of low,medium or high,and a name,which is a string of arbitrary length.The definition of the queue is given below,where front points to the first task in Q ,back points to the last task in Q .A task contains a link to the next task in Q .

typedef struct {
  task*front;
  task*back;
} task_queue;

(a)

Define a suitable enumerated type,priority ,which can take on any one of the values low ,medium or high .

 

[1]
(b)

Define a suitable data structure task ,which can be used to hold the following information about a task:

•The task priority of the task;
•The name of the task;
•A pointer next ,which will point to the next task in the queue.

 

[4]
(c)

Write a function,called IsEmpty ,the signature of which is given below,which takes in a pointer to a queue x ,and returns 1 if the queue is empty,and 0 otherwise.You may assume that an empty queue will have NULL pointers for the head and the tail.

int IsEmpty(task queue*x);

 

[3]
(d)

Write a function,called Head ,the signature of which is given below,which takes in a queue x of type task queue ,and removes the item at the head of the queue,should the queue be non empty.The item should be returned as the reference parameter y , and the function should return the number of items which have been successfully removed from the queue.

int Head(task queue*x,task*y);

[7]