can you help me to deaw the flow chart for the java code below: import java.util.Scanner; class DataItem { private int iData; public DataItem next; public DataItem(int i) { iData = i; } public int getKey() { return iData; } public void displayDataItem() { System.out.print(iData + " "); } } class SortedList { private DataItem first; public void SortedList() { first = null; } public void insert(DataItem dItem) { int key = dItem.getKey(); DataItem previous = null; DataItem current = first; while (current != null && key > current.getKey()) { previous = current; current = current.next; } if (previous == null) { first = dItem; } else { previous.next = dItem; } dItem.next = current; } public void delete(int key) { DataItem previous = null; DataItem current = first; while (current != null && key != current.getKey()) { previous = current; current = current.next; } if (previous == null) { first = first.next; } else { previous.next = current.next; } } public DataItem find(int key) { DataItem current = first; while (current != null && current.getKey() <= key) { if (current.getKey() == key) { return current; } current = current.next; } return null; } public void displayList(int index) { System.out.print("[" + index + "] => "); DataItem current = first; while (current != null) { current.displayDataItem(); current = current.next; } System.out.println(""); } } class HashTable { private SortedList[] hashArray; private int arraySize; public HashTable(int size) { arraySize = size; hashArray = new SortedList[arraySize]; for (int j = 0; j < arraySize; j++) { hashArray[j] = new SortedList(); } } public void displayTable() { for (int j = 0; j < arraySize; j++) { hashArray[j].displayList(j); } } public int hashFunc(int key) { return key % arraySize; } public void insert(DataItem dItem) { int key = dItem.getKey(); int hashVal = hashFunc(key); hashArray[hashVal].insert(dItem); } public void delete(int key) { int hashVal = hashFunc(key); hashArray[hashVal].delete(key); } public DataItem find(int key) { int hashVal = hashFunc(key); DataItem theLink = hashArray[hashVal].find(key); return theLink; } } class HashTableApp { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int aKey; DataItem aDataItem; int size = 100; System.out.println("##----HashTable App----##"); System.out.print("\nEnter size of hash table: "); size = aKey = scan.nextInt(); HashTable hashTableObj = new HashTable(size); boolean quit = false; while (quit == false) { System.out.println("\nEnter your choice number from the following: "); System.out.println("1. Print HashTable \n2. Insert Item \n3. Delete Item \n4. Find Item By Key \n5. Quit"); System.out.print("Your choice = "); int choice = scan.nextInt(); switch (choice) { case 1: hashTableObj.displayTable(); break; case 2: System.out.print("\nEnter key value to insert: "); aKey = scan.nextInt(); aDataItem = new DataItem(aKey); hashTableObj.insert(aDataItem); break; case 3: System.out.print("\nEnter key value to delete: "); aKey = scan.nextInt(); hashTableObj.delete(aKey); break; case 4: System.out.print("\nEnter key value to find: "); aKey = scan.nextInt(); aDataItem = hashTableObj.find(aKey); if (aDataItem != null) { System.out.println("Found " + aKey); } else { System.out.println("Could not find " + aKey); } break; case 5: quit = true; System.out.println("\nThanks for using --HashTableApp- -\n"); break; default: System.out.print("\nInvalid entry\n"); } } while (quit == false); } }
can you help me to deaw the flow chart for the java code below:
import java.util.Scanner;
class DataItem {
private int iData;
public DataItem next;
public DataItem(int i) {
iData = i;
}
public int getKey() {
return iData;
}
public void displayDataItem() {
System.out.print(iData + " ");
}
}
class SortedList {
private DataItem first;
public void SortedList() {
first = null;
}
public void insert(DataItem dItem) {
int key = dItem.getKey();
DataItem previous = null;
DataItem current = first;
while (current != null && key > current.getKey()) {
previous = current;
current = current.next;
}
if (previous == null) {
first = dItem;
} else {
previous.next = dItem;
}
dItem.next = current;
}
public void delete(int key) {
DataItem previous = null;
DataItem current = first;
while (current != null && key != current.getKey()) {
previous = current;
current = current.next;
}
if (previous == null) {
first = first.next;
} else {
previous.next = current.next;
}
}
public DataItem find(int key) {
DataItem current = first;
while (current != null && current.getKey() <= key) {
if (current.getKey() == key) {
return current;
}
current = current.next;
}
return null;
}
public void displayList(int index) {
System.out.print("[" + index + "] => ");
DataItem current = first;
while (current != null) {
current.displayDataItem();
current = current.next;
}
System.out.println("");
}
}
class HashTable {
private SortedList[] hashArray;
private int arraySize;
public HashTable(int size) {
arraySize = size;
hashArray = new SortedList[arraySize];
for (int j = 0; j < arraySize; j++) {
hashArray[j] = new SortedList();
}
}
public void displayTable() {
for (int j = 0; j < arraySize; j++) {
hashArray[j].displayList(j);
}
}
public int hashFunc(int key) {
return key % arraySize;
}
public void insert(DataItem dItem) {
int key = dItem.getKey();
int hashVal = hashFunc(key);
hashArray[hashVal].insert(dItem);
}
public void delete(int key) {
int hashVal = hashFunc(key);
hashArray[hashVal].delete(key);
}
public DataItem find(int key) {
int hashVal = hashFunc(key);
DataItem theLink = hashArray[hashVal].find(key);
return theLink;
}
}
class HashTableApp {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int aKey;
DataItem aDataItem;
int size = 100;
System.out.println("##----HashTable App----##");
System.out.print("\nEnter size of hash table: ");
size = aKey = scan.nextInt();
HashTable hashTableObj = new HashTable(size);
boolean quit = false;
while (quit == false) {
System.out.println("\nEnter your choice number from the
following: ");
System.out.println("1. Print HashTable \n2. Insert Item \n3.
Delete Item \n4. Find Item By Key \n5. Quit");
System.out.print("Your choice = ");
int choice = scan.nextInt();
switch (choice) {
case 1:
hashTableObj.displayTable();
break;
case 2:
System.out.print("\nEnter key value to insert: ");
aKey = scan.nextInt();
aDataItem = new DataItem(aKey);
hashTableObj.insert(aDataItem);
break;
case 3:
System.out.print("\nEnter key value to delete: ");
aKey = scan.nextInt();
hashTableObj.delete(aKey);
break;
case 4:
System.out.print("\nEnter key value to find: ");
aKey = scan.nextInt();
aDataItem = hashTableObj.find(aKey);
if (aDataItem != null) {
System.out.println("Found " + aKey);
} else {
System.out.println("Could not find " + aKey);
}
break;
case 5:
quit = true;
System.out.println("\nThanks for using --HashTableApp-
-\n");
break;
default:
System.out.print("\nInvalid entry\n");
}
}
while (quit == false);
}
}
Step by step
Solved in 2 steps with 1 images