Introduction to Programming in Python, Aug-Dec 2011 Assignment 6 Due Monday, 24 October, 2011 ---------------------------------------------------------------------- Instructions ** IMPORTANT: Note new policy regarding naming of zip file ** 1. For each question, write a separate Python program with the filename indicated in the question. Zip your solutions into a single archive. Use your CMI username to name the zip file (e.g. "madhavan.zip") and submit the zip file via moodle. If you don't name your zip file or the enclosed Python file correctly, you risk losing marks. 2. If the question asks for a function, you *must* write a function in Python (i.e., def f(x): ... ) Ensure that the function you define has the name indicated in the question. Also ensure that your function returns the value asked for, rather than printing it. If you add code to your file to test your function, make sure you *remove* this code when you submit your solution. The Python file you submit should have *only* the function definition. ---------------------------------------------------------------------- NOTE: This assignment contains only one problem. It is a reworking of Assignment 5 using Python classes. Filename: heapclass.py Write a Python class that implements max-heaps. The class should be called Heap. An object h of type Heap should support the following operations: h.deletemax() : deletes and returns the maximum element from the heap and updates the heap accordingly This function should raise an IndexError exception with a suitable message if the heap is empty. h.insertheap(val) : inserts val into the heap h h.heapsize() : returns the number of elements in the heap str(h) : returns a suitable string describing contents of h When creating a heap, the default should be to create an empty heap. However, it should also be possible to supply an initial list of values to be put into the heap. For example: h1 = Heap() # Creates an empty heap h2 = Heap([1,11,2,31]) # Creates a heap containing {1,11,2,31} Note that the user supplies the initial values as a list, in arbitrary order. The class definition should ensure that these values are organised as a max-heap. ======================================================================