My question is, for inserting ( "Dave", 23)
How I can let the computer knows this items should be place in Bucket #10?
Any algorithm can do it?
thanks for advise.
Here is my expected output:
Bucket #0 contains: [Carol,29]
Bucket #1 contains:
Bucket #2 contains: [Fred,45]
Bucket #3 contains:
Bucket #4 contains: [Lori,38]
Bucket #5 contains:
Bucket #6 contains:
Bucket #7 contains: [Sue,20]
Bucket #8 contains: [Jane,26] [Joe,18]
Bucket #9 contains:
Bucket #10 contains:
Bucket #11 contains: [Dave,23]
Bucket #12 contains:
Bucket #13 contains:
Bucket #14 contains:
Bucket #15 contains: [James,27]
Bucket #16 contains: [Mark,34]
Bucket #17 contains: [Beth,25]
Bucket #18 contains:
Bucket #19 contains:
Dave's value is: 23
Sue's value is: 20
Mark's value is: 34
Fred's value is: 45
Jane's value is: 26
Carol's value is: 29
Joe's value is: 18
Lori's value is: 38
James' value is: 27
Beth's value is: 25
and this is the HashTableTest.cpp
Code:
//HashTableTest.cpp
#include <cstdlib>
#include <iostream>
#include "hashtable.h"
using namespace std;
int main() {
HashTable<string,int> hashTable;
//hashTable.dump();
hashTable.insertItem( "Dave", 23 );
hashTable.insertItem( "Sue", 20 );
hashTable.insertItem( "Mark", 34 );
hashTable.insertItem( "Fred", 45 );
hashTable.insertItem( "Jane", 26 );
hashTable.insertItem( "Carol", 29 );
hashTable.insertItem( "Joe", 18 );
hashTable.insertItem( "Lori", 38 );
hashTable.insertItem( "James", 27 );
hashTable.insertItem( "Beth", 25 );
cout << endl << endl;
hashTable.dump();
cout << endl << endl;
cout << "Dave's value is: " << hashTable.getItem( "Dave" ) << endl;
cout << "Sue's value is: " << hashTable.getItem( "Sue" ) << endl;
cout << "Mark's value is: " << hashTable.getItem( "Mark" ) << endl;
cout << "Fred's value is: " << hashTable.getItem( "Fred" ) << endl;
cout << "Jane's value is: " << hashTable.getItem( "Jane" ) << endl;
cout << "Carol's value is: " << hashTable.getItem( "Carol" ) << endl;
cout << "Joe's value is: " << hashTable.getItem( "Joe" ) << endl;
cout << "Lori's value is: " << hashTable.getItem( "Lori" ) << endl;
cout << "James' value is: " << hashTable.getItem( "James" ) << endl;
cout << "Beth's value is: " << hashTable.getItem( "Beth" ) << endl;
return EXIT_SUCCESS;
}
How I can let the computer knows this items should be place in Bucket #10?
Any algorithm can do it?
thanks for advise.
Here is my expected output:
Bucket #0 contains: [Carol,29]
Bucket #1 contains:
Bucket #2 contains: [Fred,45]
Bucket #3 contains:
Bucket #4 contains: [Lori,38]
Bucket #5 contains:
Bucket #6 contains:
Bucket #7 contains: [Sue,20]
Bucket #8 contains: [Jane,26] [Joe,18]
Bucket #9 contains:
Bucket #10 contains:
Bucket #11 contains: [Dave,23]
Bucket #12 contains:
Bucket #13 contains:
Bucket #14 contains:
Bucket #15 contains: [James,27]
Bucket #16 contains: [Mark,34]
Bucket #17 contains: [Beth,25]
Bucket #18 contains:
Bucket #19 contains:
Dave's value is: 23
Sue's value is: 20
Mark's value is: 34
Fred's value is: 45
Jane's value is: 26
Carol's value is: 29
Joe's value is: 18
Lori's value is: 38
James' value is: 27
Beth's value is: 25
and this is the HashTableTest.cpp
Code:
//HashTableTest.cpp
#include <cstdlib>
#include <iostream>
#include "hashtable.h"
using namespace std;
int main() {
HashTable<string,int> hashTable;
//hashTable.dump();
hashTable.insertItem( "Dave", 23 );
hashTable.insertItem( "Sue", 20 );
hashTable.insertItem( "Mark", 34 );
hashTable.insertItem( "Fred", 45 );
hashTable.insertItem( "Jane", 26 );
hashTable.insertItem( "Carol", 29 );
hashTable.insertItem( "Joe", 18 );
hashTable.insertItem( "Lori", 38 );
hashTable.insertItem( "James", 27 );
hashTable.insertItem( "Beth", 25 );
cout << endl << endl;
hashTable.dump();
cout << endl << endl;
cout << "Dave's value is: " << hashTable.getItem( "Dave" ) << endl;
cout << "Sue's value is: " << hashTable.getItem( "Sue" ) << endl;
cout << "Mark's value is: " << hashTable.getItem( "Mark" ) << endl;
cout << "Fred's value is: " << hashTable.getItem( "Fred" ) << endl;
cout << "Jane's value is: " << hashTable.getItem( "Jane" ) << endl;
cout << "Carol's value is: " << hashTable.getItem( "Carol" ) << endl;
cout << "Joe's value is: " << hashTable.getItem( "Joe" ) << endl;
cout << "Lori's value is: " << hashTable.getItem( "Lori" ) << endl;
cout << "James' value is: " << hashTable.getItem( "James" ) << endl;
cout << "Beth's value is: " << hashTable.getItem( "Beth" ) << endl;
return EXIT_SUCCESS;
}