I am trying to create a hash table with linear probing. So, i am not wanting to use link list. I cant figure out what PRIVATE data members i will need. Can someone please help me out because the book i have uses link list and i am not sure what i need to get me going?
The information about each stock or mutual fund that i want to keep track of is:
* ticker symbol (e.g., IBM for International Business Machines)
* stock or fund name (e.g. International Business Machines)
* share price (e.g. 25.73)
(this should be stored as an int, not as a float or a double)
* Date of that share price (e.g. May, 23, 1967)
I will appreciate any help. I need to get going on this
Code:
#include "stock.h"
class hashmap
{
public:
hashmap(int capacity);
~hashmap(void);
// Gets the stock associated with the provided stock symbol from the hashmap,
// returns true if successful, false if not.
//
// Additional data returned:
// symbolHash: result of applying hashStr() to stock symbol
// hashIndex: array index produced by applying the modulo operator
// to the hash value produced by hashStr()
// usedIndex: array index where the stock was actually found
bool get(char const * const symbol, stock& s,
int& symbolHash, int& hashIndex, int& usedIndex) const;
// Adds the stock to the hashmap, returns true if successful,
// false if not (if the symbol is already present as a key or
// if the hash table was already full).
//
// Additional data returned:
// symbolHash: result of applying hashStr() to stock symbol
// hashIndex: array index produced by applying the modulo operator
// to the hash value produced by hashStr()
// usedIndex: array index where the stock will actually be stored
bool put(const stock& s, int& symbolHash, int& hashIndex, int& usedIndex);
// Removes the stock associated with the provided symbol from the hashmap,
// returns true if successful, false if not (if the symbol is not present as a key).
// Returns a copy of the stock in s.
//
// Additional data returned:
// symbolHash: result of applying hashStr() to stock symbol
// hashIndex: array index produced by applying the modulo operator
// to the hash value produced by hashStr()
// usedIndex: array index where the stock was actually found
bool remove(char const * const symbol, stock &s,
int& symbolHash, int& hashIndex, int& usedIndex);
friend ostream& operator<<(ostream& out, const hashmap& h);
private:
static int hashStr(char const * const symbol); // hashing function
};
Code:
#include "date.h"
using namespace std;
class stock
{
public:
stock(char const * const symbol, char const * const name, int sharePrice, date priceDate);
// sharePrice is given as a number of CENTS
stock(const stock& s); // copy constructor
stock(void); // default constructor
char const * const getSymbol(void) const;
stock& operator=(const stock& s);
stock& operator=(stock const * const s);
~stock(void);
// display column headers
static void displayHeaders(ostream& out); // display the headers when this instance is printed
// prints share price as DOLLARS
// (e.g. 2483 would print out as 24.83 and 200 would print out as 2.00)
friend ostream& operator<<(ostream& out, const stock& s);
friend class hashmap;
private:
int sharePrice; // not sure if these are what i want
char* name;
char* symbol;
date priceDate;
};
Code:#include "hashmap.h"
hashmap::hashmap(int capacity): capacity(capacity), hashTable( new item[capacity])
{
}
hashmap::~hashmap(void)
{
}
bool hashmap::get(char const * const symbol, stock& s,
int& symbolHash, int& hashIndex, int& usedIndex) const
{
//hashIndex = this->hashStr(symbol);
return false;
}
bool hashmap::put(const stock& s, int& symbolHash, int& hashIndex, int& usedIndex)
{
hashIndex = this->hashStr( s.symbol );
symbolHash = (int&)s.symbol;
usedIndex = hashIndex;
return false;
}