Hash Table - Multiple pointers

Hey,

I'm programming some sort of hash table using a double pointer to linked lists. The relevant code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Node{
private:
	std::string word;
	int frequency;
public:
        Node *next;
...
}

class Table{
private:
	Node **row;
	int size;
...
}

Table::Table(int s) {
	size=s;
	*row= new Node[size];
	for(int i=0;i<size;i++) {
		row[i] = new Node;
	} 
}

void Table::add(Node* n) {
	int key= calc_key((*n).get_Word(),size);
	if((row[key])!=0) {
		Node* temp = row[key];
		while(temp->next!=0) {
			temp=temp->next;
			}
		temp->next=n;
                delete temp;
		}
	else row[key]=n;
}


Size represents the amount of different linked lists I want to add to my hash_table (I'm using this system to avoid key-clashes).
There seems to be a problem in my add function, which seems to originate from the way I initiate my Table. When I want to add a Node to my Table (in my main function), the compiler never seems to notice my Table is still empty and the pointers are NULLpointers.
Last edited on
BUMP
lines 28/33. delete without a new.
Topic archived. No new replies allowed.