Hash Table Help (Insertion)

I am working on a problem in which I need to read from one hashtable and insert it
into another using a new hash sum. Currently though I am not getting it to insert anything into the table. What am I doing wrong


Header
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
struct Movie{
	std::string title; 
	Movie *next;
	Movie(){};
	Movie(std::string in_title){
		title = in_title;
		next = NULL;
	}
};

class HashTable
{
	public:
		HashTable();
		~HashTable();
                void createNewHashTable();
	private:
		int hashSum(std::string x, int tablesize);
	      int hashSum2(std::string x, int s);
		int tableSize;
		Movie * hashTable[10];
	      Movie * newHashTable[10];
};


New Hash Function
1
2
3
4
5
6
7
8
9
10
int HashTable::hashSum2(string inputString, int hashLen)
{
    int sum = 0;
    for (int i = 0; i < inputString.length(); i++){
	if(i%2==0)
	    sum = sum + inputString[i];
    }
    sum = sum % hashLen;
    return sum;
}


Create New Function <---- problem is here
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void HashTable::createNewHashTable(){
    for(int i = 0; i < 10; i++){
        Movie *temp3 = hashTable[i];
        while(temp3->next != NULL){
            string value = temp3->title;
            int index = hashSum2(value,10);
            Movie *temp = new Movie;
            temp->title = value;
            temp->next = NULL;
            if(newHashTable[index]->next == NULL){
                newHashTable[index]->next = temp;
            }
            else{
                Movie *temp2 = newHashTable[index];
                while (temp2->next != NULL){
                    temp2 = temp2->next;
                    temp->next = temp2;
                }
            }
            temp3 = temp3->next;
        }
    }
}
Last edited on
Topic archived. No new replies allowed.