(Due Date: friday 16th, april)

Question 1:

Design a structure Stack that represents a stack of elements of some arbitrary type. Include the following functions:

create: takes no arguments (or formally unit type as argument), and returns an empty stack.
push: takes a stack element and a stack, adds it to the top of the stack and returns the resulting stack.
pop: takes a stack, deletes the top element and returns the resulting stack.
top: takes a stack and returns the top element.
isEmpty: takes a stack and tests whether it is empty or not, and returns the boolean result.

Also include an exception EmptyStack to catch attempts to read or pop the top element of an empty stack.

Question 2:

Design a structure PQueue that represents a priority queue of elements of integer type. Include the following operations:

create: takes no arguments (or formally unit type as argument), and returns an empty queue.
enqueue: takes an element and a priority queue, and adds the element into the appropriate place in the queue, and then returns the resulting queue.
dequeue: takes a queue, and returns a pair consisting of the first element in the queue and the rest of the queue.
isEmpty: takes a queue, tests whether it is empty or not, and then returns the resulting boolean value.

Also include the exception EmptyQueue to catch attempts at dequeueing from the empty queue.

PS: Make the following assumption: "The lower the integer the greater its priority"