コード例 #1
0
        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");
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public void addItemToTable(Node temp)
        {
            HashingAlgorithm ha = new HashingAlgorithm(numberHashValues);
            int hashedValue     = 0;

            hashedValue = ha.hashThis(temp.getFirstName()); // hash key value in node by calling HashingAlgorithm

            if (theLinkedListHeads[hashedValue] == null)    //unique new value
            {                                               //this is where you assign head for hashedValue to the new node, temp
                IO.displayMessageFromProgram(temp.getFirstName() + " is a unique value");

                theLinkedListHeads[hashedValue] = temp; //put node in hash table at location theLinkedListHeads[hashedValue]
            }
            else
            {//this is where you add the node to the ordered linked list
                IO.displayMessageFromProgram(temp.getFirstName() + " replicates a hash value already in the table, "
                                             + theLinkedListHeads[hashedValue].getFirstName());

                LinkedList thisList = new LinkedList(theLinkedListHeads[hashedValue]);
                thisList.addNodeToList(temp);

                theLinkedListHeads[hashedValue] = thisList.getHead();//resets head
            }
        }