Question: please use java thanks. do not need to compile, just write the code. the LinkedHashSet code is: import java.util.Iterator; import java.util.NoSuchElementException; public class LinkedHashSet implements

please use java thanks. do not need to compile, just write the code. please use java thanks. do not need to compile, just writethe code.the LinkedHashSet code is: import java.util.Iterator; import java.util.NoSuchElementException; public class LinkedHashSetimplements Set { private LinkedList[] array; private int size; @SuppressWarnings("unchecked") public LinkedHashSet(intthe LinkedHashSet code is:

import java.util.Iterator;

import java.util.NoSuchElementException;

public class LinkedHashSet implements Set

{

private LinkedList[] array;

private int size;

@SuppressWarnings("unchecked")

public LinkedHashSet(int capacity)

{

array = new LinkedList[capacity];

for (int i = 0; i

{

array[i] = new LinkedList();

}

}

public int size()

{

return size;

}

private LinkedListIterator findMatch(T item)

{

// You must implement this method.

return null;

}

public T getMatch(T item)

{

LinkedListIterator iterator = findMatch(item);

if (item.equals(iterator.getValue()))

{

return iterator.getValue();

}

else

{

return null;

}

}

public T add(T item)

{

// You must implement this method.

return null;

}

public T remove(T item)

{

// Implementing this method is optional.

throw new UnsupportedOperationException();

}

public Iterator iterator()

{

return new IteratorImpl(array);

}

// Static nested class (see extra material on inner classes)

private static class IteratorImpl implements Iterator

{

private int index = -1;

private LinkedList[] array;

private Iterator llIterator;

private IteratorImpl(LinkedList[] array)

{

this.array = array;

findNext();

}

private void findNext()

{

do

{

index++;

}

while(index

llIterator = index

}

public boolean hasNext()

{

return index

}

public T next()

{

if (!hasNext())

{

throw new NoSuchElementException();

}

T result = llIterator.next();

if (!llIterator.hasNext())

{

findNext();

}

return result;

}

}

}

1 Linked-List Hash Tables In lecture, we implemented linear probing as one technique for resolving collisions in a hash table. An alternative is to store an array of linked lists as the hash table. Whereas linear probing searches for an empty array index that is merely close to an element's hash index, a linked-list implementation allows each element to be inserted into a linked list at its exact hash index. The linked list allows us to have multiple elements at each index of the array, so collisions become a non-issue. There is a file on Moodle called LinkedHashSet.java that contains the start of an implementation of a hash table using linked lists. The iterator ) method has been taken care of for you, as has a constructor that initializes an array of linked lists and a size field. getMatch has been partially implemented, but depends on a subroutine called findMatch ) that you must implement. findMatch 0 should take an item as a parameter and do the following: 1. Use the item's hashCode () method to generate an array index. (Refer to the implementation of HashSet from lecture if you're not sure how to map a hashCode to an array index.) 2. Obtain a LinkedListIterator from the linked list at the index obtained in step 1 3. Advance the iterator until a call of getValue to the iterator returns the item you are searching for, or until the iterator has reached the end of the list

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!