C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Confusion about writting an insert() for a Hash Table...

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
joenchinghkg
Guest





PostPosted: Sat Apr 30, 2005 4:31 am    Post subject: Confusion about writting an insert() for a Hash Table... Reply with quote



I am going to create an method to insert Items inside the hash table,
However, i don't really know what I should code inside the method.

Should I use push or pop because it is based on a list container for my
private attribute.

Here is my code.
hashtable.h
Code:

//HashTable.h
#ifndef HASHTABLE_H
#define HASHTABLE_H

#include <list>

using namespace std;

template <typename KEYTYPE, typename VALUETYPE>
class HashTable
{
public:

void insertItem( const string& key, const VALUETYPE& value
);
VALUETYPE getItem( const string& key ) const;

void dump() const;

private:


enum { TABLESIZE = 20 };

struct KeyValuePair {
KEYTYPE key;
VALUETYPE value;
};


list<KeyValuePair> hashTable[ TABLESIZE ];


unsigned getIndex( const char* key ) const; // Hash Function


};

#include "hashtable.tem"

#endif



hashtable.tem
Code:

//hashtable.tem
template <typename KEYTYPE, typename VALUETYPE>
void HashTable<KEYTYPE,VALUETYPE>::insertItem( const string& key, const
VALUETYPE& value ) {


}

template <typename KEYTYPE, typename VALUETYPE>
void HashTable<KEYTYPE,VALUETYPE>::dump() const {

for( unsigned iCtr = 0; iCtr < TABLESIZE; iCtr++ ) {

cout << "Bucket #" << iCtr << " contains: ";

list for( iter = hashTable[ iCtr ].begin(); iter != hashTable[ iCtr
].end(); ++iter ) {
cout << '[' << iter->key.c_str() << ',' << iter->value << ']'
<< ' ';
}

cout << endl;
}
}

// End of file

;)



Thanks for advice

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.