Question: Can someone please provide inline comments on this code so I understand what each function is doing and why? class LinearProbing { private Integer[] value
Can someone please provide inline comments on this code so I understand what each function is doing and why?
class LinearProbing { private Integer[] value = new Integer[13]; private Integer count = 0; private boolean resize = false; private Integer length(Integer element) { return (element) % value.length; } private Float factoring() { return (float) count / value.length; } private Integer probing(Integer x){ int hf = length(x); while(value[hf] != null) { hf = (hf + 1) % value.length; } return hf; } private void alter() { resize = true; Integer[] value1 = value; if(factoring() >= 0.5) { value = new Integer[value1.length * 2]; for (Integer integer : value1) { if (integer != null) { Add(integer); } } } else if(factoring() <= 0.25 && value1.length > 13) { value = new Integer[value1.length / 2]; for (Integer integer : value1) { if (integer != null) { Add(integer); } } } resize = false; } public void Add(Integer element) { Integer hashtable = probing(element); value[hashtable] = element; if(!resize) { count++; alter(); } } public void Display() { for (Integer integer : value) { if (integer != null) { System.out.println(integer); } } } } class LHProbing { public static void main(String[] args) { int [] List = {1,5,21,26,39,14,15,16,17,18,19,20,111,145,146}; LinearProbing LP = new LinearProbing(); for (int j : List) { LP.Add(j); } LP.Display(); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
