ClassS04CS141/Prog1

ClassS04CS141 | ClassS04CS141 | recent changes | Preferences

Showing revision 28
The assignment is to implement two basic data structures: a growable array (part 1) and a hash table (part 2).

Turn in the full assignment by the due date: April 12, 2004 at 5pm.

In all cases, you are free to change the *.h files (in fact you may have to). Just make sure the public part of the interface stays the same.

For prog asst 1, you can use the standard template library or the C++ standard library to implement the member functions in the *.cc files if you want. This will require changing the private data and function members in the *.h files. That's okay, just make sure your implementation has the correct time complexity for its operations.

Part 1 is here. (Part 2, below, subsumes part 1.)

Part 2:

1. Download and read the AssocList? class. The files are /AssocList.h and /AssocList.cc . This class implements the same functionality as the HashTable class will, but most operations take linear time. You will also need /Comparisons.h . Please do this before week 2 lab.

2. Modify your Array class from part 1:

a. Make the class "const correct" by adding the const keyword and adding a const operator[].
b. Add a copy constructor, an assignment operator (operator=), and a clear() member function that empties the array.
c. Add the following functionality. Add a constructor that takes a VALUE argument, which is then to be used to initialize every new cell (instead of 0). Change the constructor that takes no arguments so that an Array constructed with that constructor does not initialize new cells at all.

An example of a suitable Array.h file is /Array.h . Your Array.h file should agree with this one on all public parts of the interface.
Also, add the following (or some equivalent) to your Array.cc for printing Arrays:
template <class KEY>
ostream & 
operator<<(
	   ostream & out, 
	   const Array<KEY> & a) {
  out << "[";
  for (int i = 0;  i < a.size();  ++i) {
    if (i != 0) out << ", ";
    out << a[i];
  }
  out << "]";
  return out;
}

3. Implement the HashTable class. Download /Hash.h . Your job is to change Hash.h as necessary and implement Hash.cc. The private part of the HashTable interface in Hash.h is appropriate for an implementation that stores (KEY, VALUE) pairs in an Array<AssocList?<KEY,VALUE> >, where the i'th element of the Array holds the KEY,VALUE pairs with KEY hashing to i. Your hash table should grow appropriately so that most buckets have O(1) elements (assuming a good hash function).

4. Download the simple test routine /Test1.cc . Update your Makefile to make Test1 from Test1.cc with the appropriate dependencies.

Due date and turn in

Your assignment must be turned in by Monday, April 12 at 5pm.

You will turn in the following files: Array.h, Array.cc, AssocList.h?, AssocList.cc?, Hash.h, Hash.cc, Makefile .

Turn in will be here: https://www.cs.ucr.edu/ (not yet working).

Your AssocList.cc? and all *.h files may be essentially the same as the ones given out, although they need not be.

Remember to add the header with your identifying information to each file (/ReportTemplateHeader).

A few days before the due date, this page will be updated with information about turning in assignments.


ClassS04CS141 | ClassS04CS141 | recent changes | Preferences
This page is read-only | View other revisions | View current revision
Edited April 5, 2004 3:27 pm by Neal (diff)
Search: