Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. // File:hashTable.cpp
  2. // hashTable Class implementation file
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. // Constructor with argument, size is nelements, default is 11
  7. template <class keyType, class dataType>
  8. hashTable<keyType, dataType>::hashTable(int nelements)
  9. {
  10. //Set Maximum Size = nelemts
  11. //Allocate memory
  12. //Initialize h (the index to a slot) to -1
  13. //Initialize csize (current size)
  14. }
  15. // Destructor
  16. template <class keyType, class dataType>
  17. hashTable<keyType, dataType>::~hashTable()
  18. { //Free allocated memory
  19. }
  20. // Empty all slots in the table (Fill table with Empty key)
  21. template <class keyType, class dataType>
  22. void hashTable<keyType, dataType>::emptyTable(const keyType &k)
  23. {
  24. //Set the empty value = k
  25. //Loop to put the Empty (k) value in all table slots
  26. //Initialize h (index to a slot) to -1
  27. //Initialize current size csize to 0
  28. }
  29.  
  30. // return True if table is empty
  31. template <class keyType, class dataType>
  32. bool hashTable<keyType, dataType>::tableIsEmpty() const
  33. {
  34. //Test current size (csize)
  35. }
  36.  
  37. // return True if table is full
  38. template <class keyType, class dataType>
  39. bool hashTable<keyType, dataType>::tableIsFull() const
  40. {
  41. //Test current size (csize)
  42. }
  43.  
  44. // insert key and data at a hashed slot
  45. template <class keyType, class dataType>
  46. bool hashTable<keyType, dataType>::insert(const keyType &k, const dataType &d)
  47. {
  48. /*if table is not full
  49. find (h) using the hash function passing to it (k)
  50. loop until find an empty slot (circular array: h = (h+1) % MaxSize)
  51. insert key and data at the found empty slot (h)
  52. return true;
  53. else return false;
  54. */
  55. }
  56.  
  57. // Search the table for the slot that matches key.
  58. // If found, return True, set current position to slot
  59. template <class keyType, class dataType>
  60. bool hashTable<keyType, dataType>::search(const keyType &k)
  61. {
  62.  
  63. /*if table is not empty
  64. {
  65. find h by calling the hash function passing to it k
  66. int start = h; //keep the starting point
  67. for ( ; ; ) loop until either found or reach empty slot or reach start again
  68. {
  69. if slot h is empty return false; //not found
  70. if there is a match at h return true; //found
  71. h = (h+1) % MaxSize; //move to next slot
  72. if (h == start) return false; //Back to start again
  73. }
  74. }
  75. else return false;
  76. */
  77. }
  78.  
  79. // Private Hashing Function
  80. template <class keyType, class dataType>
  81. int hashTable<keyType, dataType>::hash(const keyType &k) const
  82. {
  83. return (k % MaxSize);
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement