notes19 - September 22nd A template hash table W...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
September 22 nd A template hash table W implemented a hash table which mapped a char * (key) to a void * (item) We are going to implement a C++ template so the items stored in the hash table can have any type. The keys are still Strings (char *). char * (key) → <type> (item) eg. char * → int Templates are defined in a .h file and included with #include where they are needed. HashTable.h #include <stdlib.h> #include <string.h> //Hash table node struct template < typename Data > struct HashTableEntry { const char * key ; Data data ; HashTableEntry * next ; }; //Hash table class template < typename Data > class HashTable { private : enum { TableSize = 2039 }; HashTableEntry < Data >** buckets ; //array of pointers int hash ( const char * key ); public : HashTable (); //Returns true if key exists. Substitute data if key exists bool insertItem ( const char * key , Data data ); //Returns true if key exists. Puts data into the 'data' pointer bool find ( const char * key , Data * data ); //Removes element with the given key bool
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/02/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue University-West Lafayette.

Page1 / 5

notes19 - September 22nd A template hash table W...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online