public void initializeNode(Node temp, InputsAndOutputs IO) { //ask for first name temp.setFirstName(IO.obtainStringInputFromUser("first name ")); //ask for last name temp.setLastName(IO.obtainStringInputFromUser("last name ")); }
private void addNodeToTheTable(InputsAndOutputs IO) { HashingAlgorithm ha = new HashingAlgorithm(); Node tempNode = new Node(); initializeNode(tempNode, IO); int n = ha.hashThis(tempNode.getFirstName()); theLinkedList = theHashTable.retrieveOneHashedList(n); theHashTable.addItemToTable(tempNode); //Node tempNode = new Node(); //initializeNode(tempNode, IO); //theHashTable.addItemToTable(tempNode); }
public void findNodeInList(InputsAndOutputs IO) { HashingAlgorithm ha = new HashingAlgorithm(numberHashValues); String findName = IO.obtainStringInputFromUser("what first name should we find?"); int findHash = ha.hashThis(findName); //needs to be something in the head to find it if (theLinkedListHeads[findHash].getFirstName().Equals(findName)) { IO.displayMessageFromProgram("found " + findName + " in the table at hash value " + findHash); } else { IO.displayMessageFromProgram(findName + " is not in the table"); } }
//private Node[] theLinkedListHeads = null; //HashTable ht = new HashTable(); public ControlTable() { InputsAndOutputs IO = new InputsAndOutputs(); String choice; String menu = "Hash Table\n"; menu += "0 - exit\n"; menu += "1 - add node to the table\n"; menu += "2 - find a node in the hash table\n"; menu += "3 - look at all the nodes in the hash table\n"; while (true) { choice = IO.obtainStringInputFromUser(menu); switch (choice[0]) { case '0': Environment.Exit(0); break; case '1': addNodeToTheTable(IO); break; case '2': theHashTable.findNodeInList(IO); break; case '3': lookAtTheTheHeadsInTheTable(); break; } } }