works in both chained linked list version and linear probe version