Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.image text in transcribedimage text in transcribedimage text in transcribedthe 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions

Question

Explain the factors influencing wage and salary administration.

Answered: 1 week ago

Question

Examine various types of executive compensation plans.

Answered: 1 week ago

Question

1. What is the meaning and definition of banks ?

Answered: 1 week ago

Question

2. What is the meaning and definition of Banking?

Answered: 1 week ago