I am new to Java. I can't figure out how to do this without pointers:
// hash table with seperate chaining
class HashTbl {
class Node {
int data;
Node next;
}
private Node tbl[];
HashTbl(int size) {
tbl[] = new Node[size * 1.25];
}
public int insert(int item) {
// insert data
}
public Node lookup(int item) {
// search for item in the hashtable
// the item was found at array index 'idx'
return tbl[idx];
}
public int remove (int item) {
Node n = lookup(item);
n = null; // <--- this obviously doesn't work, what i want to do is set tbl[idx] to null
}
}
Setting the local reference variable to null doesn't affect the actual array. In c++ i would return a pointer to the array element so that i can set the array element to Null via the pointer. Now, there are no pointers in Java, so how can i make this work?
Update: returning an the array index or using a separate function that returns a the matched index are 2 possible workarounds. But i am not just looking for a solution to this particular program. What about this problem in general?