Advanced Programming, Jan-Apr 2012 Assignment 2 7 February, 2012 Due 13 February, 2012 A queue whose size is bounded by N can be implemented using a circular list (also called a circular buffer) with exactly N elements. When the (N+1)th insertq() operation happens, at least one element that was added earlier must have been removed from the queue by now, so we can "wrap around" and put the new element at the first position in the list. In general, we maintain two indices within the circular buffer to reflect the current position of the first and last elements in the underlying queue. Inserting a value moves the index pointing to the last element, possibly wrapping around to the front. Removing a value moves the index pointing to the first element, again possibly wrapping around to the front. Write a Python class that implements a bounded length queue using a circular buffer of the appropriate size. - When setting up the queue, you should pass two parameters: -- N, the size of the buffer (compulsory) This should set up a Python list of length exactly N. -- A list of values of length <= N as the initial contents of the queue (optional). The list of initial values is interpreted as though these values were inserted one by one from left to right. - Your bounded queue should support the following functions: -- qsize() : returns the number of elements currently in the queue. -- insertq(v) : insert value v at the tail. Raise an exception RuntimeError if this insert violates the bound on the queue size. -- removeq() : remove and return the value at the head. Raise an exception RuntimeError if removeq() is called on an empty queue. ---------------------------------------------------------------------- Name your class and file as follows: Class name: BoundedQueue File name : circular.py ======================================================================