notes12 - Continued from HashTableVoid.cc bool...

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

View Full Document Right Arrow Icon
Continued from HashTableVoid.cc bool HashTableVoid::insertItem(const char *key, void *data){ int h = hash(key); //find out if key already exists HashTableVoidEntry *p = _buckets[h]; p = p->_next; } if(p != NULL){ //found entry with this key //overwrite data p->_data = data; return true; } //p = NULL: entry not found //add entry to the list p = newHashTableVoidEntry(); p->_data = data; p->_next = _buckets[h]; _buckets[h] = p; p->_key = strdup(key); //store duplicate of key expandTableIfNeeded(); //expand if tableSize = n return false; } bool HashTableVoid::find(const char *key, void **data){ int h = hash(key); HashTableVoidEntry *p = _buckets[h]; //traverse the list p = p->_next; } if(p == NULL){ //key not found *data = NULL; return false; } //found an entry with this key *data = p->_data; return true; } bool HashTableVoid::removeElement(const *key){ HashTableVoidEntry *p; HashTableVoidEntry *previous; int h = hash(key); p = _buckets[h]; previous = NULL; previous = p; p = p->_next; } if(p == NULL){ //key not found return false; }
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

notes12 - Continued from HashTableVoid.cc bool...

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