1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#include<iostream>
#include<string>
#include "hasht.h"
using namespace std;
int main(void)
{
// the default class constructor
HashT htable; //bucket size is 10
// the other class constructor
HashT hashtable(7); //bucket size is 7
// Test1: add data to htable
htable.hashtable_add("David", 52); // add data to bucket 2 since hash value is 2
htable.hashtable_add("Goliath", 45); // add data to bucket 5 since hash value is 5
htable.hashtable_add("Alan", 31); // add data to bucket 1 since hash value is 1
cout << "\nTest 1: Printing Hash table with default bucket size :\n" ;
htable.hashtable_display();
// Test2: add data to hashtable
hashtable.hashtable_add("David", 52); // add data to bucket 3 since hash value is 3
hashtable.hashtable_add("Goliath", 46); // add data to bucket 4 since hash value is 4
hashtable.hashtable_add("Alan", 33); // add data to bucket 5 since hash value is 5
cout << "\nTest 2: Printing Hash table with bucket size 7 : \n" ;
hashtable.hashtable_display();
// Test3: delete data from htable
htable.hashtable_delete("David", 52); // delete data from bucket 2 since hash value is 2
cout << "\nTest 3: Printing Hash table with default bucket size :\n" ;
htable.hashtable_display();
// Test4: delete data from hashtable
hashtable.hashtable_delete("David", 52); // delete data from bucket 3 since hash value is 3
cout << "\nTest 4: Printing Hash table with bucket size 7 : \n" ;
hashtable.hashtable_display();
// Test5: add duplicate data to htable
htable.hashtable_add("Alan", 31); // data is not added since it already exists
cout << "\nTest 5: Printing Hash table with default bucket size :\n" ;
htable.hashtable_display();
// Test6: add duplicate data to hashtable
hashtable.hashtable_add("Alan", 33); // data is not added since it already exists
cout << "\nTest 6: Printing Hash table with bucket size 7 : \n" ;
hashtable.hashtable_display();
// Test7: adds multiple data items to same bucket in htable
htable.hashtable_add("Tom", 65); // add data to bucket 5 since hash value is 5
htable.hashtable_add("Alice", 51); // add data to bucket 1 since hash value is 1
htable.hashtable_add("Ben", 25); // add data to bucket 5 since hash value is 5
htable.hashtable_add("Amy", 21); // add data to bucket 1 since hash value is 1
cout << "\nTest 7: Printing Hash table with default bucket size :\n" ; //adds multiple data items to same bucket
htable.hashtable_display();
// Test8: adds multiple data items to same bucket in hashtable
hashtable.hashtable_add("Ricky", 18); // add data to bucket 4 since hash value is 4
hashtable.hashtable_add("Adrian", 19); // add data to bucket 5 since hash value is 5
hashtable.hashtable_add("Jack", 25); // add data to bucket 4 since hash value is 4
hashtable.hashtable_add("Grace", 26); // add data to bucket 5 since hash value is 5
cout << "\nTest 8: Printing Hash table with bucket size 7 : \n" ; //adds multiple data items to same bucket
hashtable.hashtable_display();
// Test9: deletes data from buckets with multiple data items in htable
htable.hashtable_delete("Ben", 25); // delete data from bucket 5 since hash value is 5
htable.hashtable_delete("Amy", 21); // delete data from bucket 1 since hash value is 1
cout << "\nTest 9: Printing Hash table with default bucket size :\n" ; //deletes data from buckets with multiple data items
htable.hashtable_display();
// Test10: deletes data from buckets with multiple data items in hashtable
hashtable.hashtable_delete("Jack", 25); // delete data from bucket 4 since hash value is 4
hashtable.hashtable_delete("Grace", 26); // delete data from bucket 5 since hash value is 5
cout << "\nTest 10: Printing Hash table with bucket size 7 : \n" ; //deletes data from buckets with multiple data items
hashtable.hashtable_display();
return 0;
}
|