Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <limits>
- #include "Hash.h"
- #include "Item.h"
- using namespace std;
- Hash hash;
- void addItem();
- void deleteItem();
- void searchItem();
- void checkIndex();
- void showBucketFromIndex();
- void showBucketFromKey();
- void showHashTable();
- int main()
- {
- cout << "\nWhat do you want to do?\n\n01. Inset/Update an Item.\n02. Delete an Item."
- << "\n03. Search for an Item.\n04. Check Hash Index for a Key.\n05. Show Bucket From an Index."
- << "\n06. Show Bucket From a Key.\n07. Show Hash Table.\n\nAny other INTEGER : Exit" << endl;
- int opinion;
- cout << "\nChoice/Opinion: "; cin >> opinion;
- switch (opinion)
- {
- case 1: addItem();
- break;
- case 2: deleteItem();
- break;
- case 3: searchItem();
- break;
- case 4: checkIndex();
- break;
- case 5: showBucketFromIndex();
- break;
- case 6: showBucketFromKey();
- break;
- case 7: showHashTable();
- break;
- default: cout << "Thanks, hope to see you again.!" << endl;
- exit(0);
- }
- return 0;
- }
- void addItem()
- {
- cin.sync();
- string name, number;
- cout << "\nName: ";
- getline(cin, name);
- cout << "Phone Number: ";
- getline(cin, number);
- Item *item = ::hash.searchItem(name);
- if (item != NULL)
- {
- item->setPhoneNumber(number);
- cout << "\nItem " << name << " has been updated." << endl;
- }
- else
- {
- ::hash.addItem(name, number);
- cout << "\nItem " << name << " has been created." << endl;
- }
- main();
- // cout << "New Entry has been added: " << name << endl;
- }
- void deleteItem()
- {
- cin.sync();
- string key;
- cout << "\nWhich contact do you wish to delete? Contact Name: ";
- getline(cin, key);
- ::hash.deleteItem(key);
- main();
- }
- void searchItem()
- {
- cin.sync();
- string key;
- cout << "\nWhich contact do you wish to search? Contact Name: ";
- getline(cin, key);
- if (Item *item = ::hash.searchItem(key))
- {
- item->show();
- }
- main();
- }
- void checkIndex()
- {
- cin.sync();
- string key;
- cout << "\nGiven KEY: ";
- getline(cin, key);
- cout << "Generated Index: " << ::hash.hashFunction(key) << endl;
- main();
- }
- void showBucketFromIndex()
- {
- int index;
- cout << "\nBucket No: "; cin >> index;
- ::hash.showBucket(index);
- main();
- }
- void showBucketFromKey()
- {
- cin.sync();
- string key;
- cout << "\nGiven Key: ";
- getline(cin, key);
- ::hash.showBucketFromKey(key);
- main();
- }
- void showHashTable()
- {
- ::hash.showHashTable();
- main();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement