I am having trouble with the (hashTable[bucket][size] == null). I was wondering how you could check to see that slot is null if null is not of type int. Any ideas/tips?
public void add(int n){
int bucket = hashF(n);
int p=0;
int size = hashTable[0].length;
for(int i=0; i>size; i++){
if(hashTable[bucket][size] == null){
hashTable[bucket][size]= n;
break;
}
if(i+1 == size){
bucket++;
i = -1;
}
if(bucket ==10){
bucket = 0;
}
p++;
if(p== hashTable.length*hashTable[0].length){
break;
}
}
for(int i=0; i<BST.length; i++){
if(BST[i] == null){
BST[i] = n;
break;
}
else if(n<BST[i]){
i= 2*i;
}
else{
i = 2*i+1;
}
}
}
Assuming that hashTable is a 2D array of ints, you cannot check if one of its elements will be null as it never will be. A primitive can never be null as it is not an object reference. It will always have a value - its default value is 0.
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html