
CSE382 – Algorithms and Data Structures Fall 2008
Lab #7 – Map<K,V> class
version 2
Prologue:
This lab is concerned with building a map class, Map<K,V>, using an
instance of a Pair<K,V> class as the type held by an instance of the
BTree<T>. That is, BTree< Pair<K,V> > is a private member of the
Map<K,V> class.
Starting Condition:
Please use only the ECS computers provided in this computer lab (CST
3-201) to implement code for this lab1. Please write all of this yourself
during class for the first part and for the second part outside of class.
Do not use any code from the college server, except as directed in
parts 1-2, below, nor any code from the web.
Tasks to be completed in class:
1. Build a new console application project that holds Pair.h, Pair.cpp files
and BTree.h, and BTree.cpp files you developed in Lab #5.
2. To the Pair.h source add prologue, and maintenance information. In
the Manual Page part add comments that describe briefly, but
completely, the interface you expect to use for the Pair<K,V> class.
Pair<K,V> should support an order relation that is determined by the
order of its key class K.
3. Build a second console application project that holds Map.h and
Map.cpp files. Define a class Map<K,V> parameterized on the key
type K, and the value type V. In that class define a private field of type
BTree< Pair<K,V> >;
4. Define a member function to insert a key and a value to the map.
5. Implement a test stub to test instances of your Map<K,V> class, using
the debugger to show that your insert function works.
Tasks to be completed outside of class:
6. Add a find function used to search for a key, and, if it exists, to return
its value.
7. Add an indexing facility to your Map<K,V> class. An instance myMap
would be indexed like this: myMap[key] = value; If key does not exist
in the map it is inserted along with value. If key does exist, value
overwrites the previous value.
8. Add code to your test stub to test instances of the, now balanced,
BTree<T> class.
Note:
You must hand in whatever you have completed in class at the end of that
class.
1 This explicitly forbids you from using your personal laptop.