Data Structures and Algorithms with Object-Oriented Design Patterns in Python
next up previous index

Projects

  1.   Design and implement suitable wrapper classes that extend the Object base class for the Python types bool, int, str, and tuple.
  2. Using visitors, devise an implementation for the __contains__ method and the find method of the SearchableContainer class declared in Program gif.
  3. Using an iterator, devise an implementation for the __contains__ method and the find method of the SearchableContainer class declared in Program gif.
  4. Devise a scheme using visitors whereby all of the objects contained in one searchable container can be removed from it and transfered to another container.
  5.   A bag  is a simple container that can hold a collection of objects. Design and implement a concrete class called Bag that extends the SearchableContainer class defined in Program gif. Use the Array class given in Chapter gif to keep track of the contents of the bag.
  6. Repeat Project gif, this time using the LinkedList class given in Chapter gif.
  7. In Java it is common to use an enumeration  as the means to iterate through the objects in a container. In Python we can define an enumeration like this:
    class Enumeration(Object):
        def hasMoreElements():
    	pass
        hasMoreElements = abstractmethod(hasMoreElements)
    
        def nextElement():
    	pass
        nextElement = abstractmethod(nextElement)
    Given an enumeration e from some container c, the contents of c can be printed like this:
    while (e.hasMoreElements()):
        print e.nextElement()
    Devise a wrapper class to encapsulate a Python iterator and provide the functionality of a Java enumeration.


next up previous index

Bruno Copyright © 2003, 2004 by Bruno R. Preiss, P.Eng. All rights reserved.