I'm trying to write a solution for linear probing in a hash table dealing with multiple "animals", similar to the one below that was given to me.
index++;
if(index == hashAnimals.length) {
index = 0;
}
if(hashAnimals[index] == null){
hashAnimals[index] = new Animal(animals.get(i));
}
But I've been told that this would simply be the solution for ONE animal, in ONE position. And so this is my current solution that I've started for multiple animals:
int index = 0;
for(int i = 0; i < hashAnimals.length) {
if(index = hashAnimals.length){
index = 0;
}
But I'm having a problem thinking about a solution of finding a free position. Should I use another for loop? If I simply copied the second if statement above in my code, I believe the "animal" that I'm trying to add would be skipped if the index was already taken, and "i" would increment to the next animal at the end of the loop.