Hash table C Can not use stl libraries ie vectors hashmap e
Hash table - C++
 Can not use stl libraries, ie. vectors, hash_map, etc.
You are to write a program to set up a data base for a phone index. The key will be a person’s name to a table that will supply the phone number. The data base must be implemented as a hash table with the names as the key. The format will be a person name (multiple parts) followed by a phone number.
Example: John Doe 601-5433 or O E Vay 921-1234. Only one name one phone number will be on an input line.
Set your hash table up to be 45 entries, hash table is 31 in size.
(1.) Print out the final data base (hash table) and indicate how many collisions were made in building the data base.
(2.) After building the Phone Index, show examples of looking up a name and returning a phone number for several names and some of invalid names.
Now I do have some folks (police usually) that have a phone number but need to know the person. So you will create a second hash key capability to use the phone number (hashed) as a key to the data base. Now you ca not create a new hash table since it is anticipated that the table will become quite large and there is only room for one copy of the data that can be maintained. You can though create an index table to access the data base above.
(3.) Print out the data base (names and phone numbers (hash table)) in the order of the phone hash keys.
(4.) Now test your phone number look up and show that it works again by returning the name and phone number of several names using the phone number as the key. Show a return of an invalid phone number
Data for program:
Taylor marie 939-1512
 james wilis thomas 261-8342
 Hewy Lewy Dewy   623-9921
 Stone Rock 544-2372
 lea high lee 266-8324
 stephens reynolds 696-9231
 mack russell 123-1234
 Lewis Michelle Tee 828-2148
 john marshall 888-2891
 Mister Rogers   924-7221
 Moto hasey 823-8000
 Oe vey 177-1423
 Twoseeor knocksee 823-8321
 Legg T.        587-2839
 Znot Noz Oozey 531-4353
 Hofstra M.      601-3225
 Malioneyh P. J. 287-4344
 Morier G. E.    544-2319
 Cray Z. Cyco   134-7242
 Hauser M.       606-2940
 Fanny Pac Jac    842-3242
 Sid MacGriddy    882-2424
 Currie W. D.    701-4281
 Antoney Wenner 999-3255
 Hoos R. Dadie   818-3821
 Smelly Tau      707-7281
 Tobe Ore Knott 613-2414
 Bee Yond Lawz   634-2454
 Tyson Chicken 602-3152
 TooB OrNot   283-5214
 SixOne Other 843-2343
 Big Tow 384-5624
 Juan Legged    882-6246
 Tau Jam       532-6871
 Zevent Heaven 834-2563
 Man Oh Mann     313-7422
 E Lec Shaun      709-7424
 Sticky Finger McRidder 829-9853
 Mighty Mouse 222-2222
 G P Morier 832-4562
Solution
#include <iostream>
 #include <cstdio>
 #include <cstdlib>
 #include <fstream>
 #include <sstream>
 #include <string>
 using namespace std;
 const int TABLE_SIZE = 31;
 
 // node structure declaring
 class HashNode
 {
 public:
 int key;
 int value;
 HashNode(int key, int value)
 {
 this->key = key;
 this->value = value;
 }
 };
 
 /*
 * DeleteHashNode Class Declaration
 */
 class DeleteHashNode:public HashNode
 {
 private:
 static DeleteHashNode *entry;
 DeleteHashNode():HashNode(-1, -1)
 {}
 public:
 static DeleteHashNode *getNode()
 {
 if (entry == NULL)
 entry = new DeleteHashNode();
 return entry;
 }
 };
 DeleteHashNode *DeleteHashNode::entry = NULL;
 //hashmap class declaration
 class HashMap
 {
 private:
 HashNode **hashTable;
        int collisions = 0;
 public:
 HashMap()
 {
 hashTable = new HashNode* [TABLE_SIZE];
 for (int i = 0; i < TABLE_SIZE; i++)
 {
 hashTable[i] = NULL;
 }
            collisions = 0;
 }
 
 ~HashMap()
 {
 for (int i = 0; i < TABLE_SIZE; i++)
 {
 if (hashTable[i] != NULL && hashTable[i] != DeleteHashNode::getNode())
 delete hashTable[i];
 }
 delete[] hashTable;
 }
 // hash function
 int hashFunction(int key)
 {
 return key % TABLE_SIZE;
 }
 // insert element
 void Insert(int key, int value)
 {
 int calculatedHashVal = hashFunction(key);
 int init = -1;
 int delete_index = -1;
 while (calculatedHashVal != init && (hashTable[calculatedHashVal]
 == DeleteHashNode::getNode() || hashTable[calculatedHashVal]
 != NULL && hashTable[calculatedHashVal]->key != key))
 {
 if (init == -1)
 init = calculatedHashVal;
 if (hashTable[calculatedHashVal] == DeleteHashNode::getNode())
 delete_index = calculatedHashVal;
 calculatedHashVal = hashFunction(calculatedHashVal + 1);
                collisions++;
 }
 if (hashTable[calculatedHashVal] == NULL || calculatedHashVal == init)
 {
 if(delete_index != -1)
 hashTable[delete_index] = new HashNode(key, value);
 else
 hashTable[calculatedHashVal] = new HashNode(key, value);
 }
 if(init != calculatedHashVal)
 {
 if (hashTable[calculatedHashVal] != DeleteHashNode::getNode())
 {
 if (hashTable[calculatedHashVal] != NULL)
 {
 if (hashTable[calculatedHashVal]->key == key)
 hashTable[calculatedHashVal]->value = value;
 }
 }
 else
 hashTable[calculatedHashVal] = new HashNode(key, value);
 }
 }
 };
 
 int main()
 {
 HashMap hash;
 int key, value;
 int choice;
    std::ifstream infile(\"input.txt\");
    std::string line;
    while (std::getline(infile, line))
    {
        std::istringstream iss(line);
        String name;
        int key;
        if (!(iss >> name >> key)) { break; } // error
        hash.insert(name,key);
    }
 return 0;
 }




