My instructor has me confused on how to do hash tabkes. His turkish accent is ve
ID: 3674331 • Letter: M
Question
My instructor has me confused on how to do hash tabkes. His turkish accent is very hard to understand. I have asked this question three times now. Can someone help me out with this hash table? I have provided the 3 Java classes for this question (Tester, SLL, Set). Please do what is in Bold in the Set class, and if you would explain it, that would be extremely helpful. Please make sure it compiles. Here at the instructions:
public class Tester{
// Have this method to display YOUR name.
static void displayName(){
System.out.println("Written by. ");
}
// DO NOT MODIFY THE MAIN METHOD
public static void main(String[] args){
displayName();
Set set1 = new Set();
Set set2 = new Set();
set1.add(13);
set1.add(23);
set1.add(33);
set1.add(13);
set1.add(54);
set1.add(75);
set2.add(15);
set2.add(26);
set2.add(26);
System.out.println("Contents of set set1: ");
set1.output();
System.out.println("Contents of set set2: ");
set2.output();
}
}
public class SLL {
public class Node {
private int data;
private Node next;
public Node() {
data = 0;
next = null;
}
public Node(int newData, Node linkValue) {
data = newData;
next = linkValue;
}
public int getData() {
return data;
}
public Node getLink() {
return next;
}
}// End of Node inner class
private Node head;
public SLL() {
head = null;
}
public void addToStart(int itemData) {
head = new Node(itemData, head);
}
public boolean contains(int item) {
return (find(item) != null);
}
public Node find(int target) {
Node position = head;
int itemAtPosition;
while (position != null) {
itemAtPosition = position.data;
if (itemAtPosition == target) {
return position;
}
position = position.next;
}
return null; // target was not found
}
public void outputList() {
Node position = head;
while (position != null) {
System.out.print(position.data + " ");
position = position.next;
}
System.out.println();
}
}
public class Set {
private SLL[] hashArray;
private int size = 10;
public Set() {
hashArray = new SLL[size];
}
private int computeHash(int s) {
return s % size;
}
public boolean contains(int item) {
int hash = computeHash(item);
SLL list = hashArray[hash];
if (list.find(item) == null)
return false;
return true;
}
// DO NOT MODIFY ANY CODE ABOVE THIS LINE
// COMPLETE BELOW
}
}
Here is the completed product:
Follow the instructions as commented in the codes. Do not have empty linked lists in your program. Create linked lists only when you need it. Remember that duplicates are not allowed in the set. Your program must work with any input correctly. Use SLL and Tester classes as they are given. Do not modify them. Use SLL and Tester classes as they are given. Do no modity them.Explanation / Answer
Inorder to add data to the SLL, it must have a setter method for next link, so it is not possible to add a new element without editing(by adding those methods). Edited code is pasted below :
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.