This is a grade 12 java HashTable assignment.
So my teacher gave me the template for doing this assignment, but it does not work :(. And he expects us to get the template to work and then do the assignment.
Here's what he gave us:
class MyHashTable<T>{
private T[] vals;
private int load;
public MyHashTable(){
load = 0;
vals = new T[10];
}
public MyHashTable(int size){
load = 0;
vals = new T[size];
}
public void add(T obj){//don't care about negatives
int size = vals.length;
if((load+1.0)/size>0.6){
size*=10;
T[] tmp = new T[size];
for(int i=0;i<size/10;i++){
if(vals[i]!=null){
add(vals[i], tmp);
}
}
vals = tmp;
}
add(obj, vals);
}
public void add(T obj, T[]vals){
int loc = Math.abs(obj.hashCode())%vals.length;
while(vals[loc]!=null){
loc = (loc+1)%vals.length;
}
vals[loc] = obj;
}
/*public boolean contains(T obj){
} */
}
it gives an error: error: generic array creation
Can anyone tell me what does that mean? With examples hopefully.