Algorithms_in_C++  1.0.0
Set of algorithms implemented in C++.
chaining.cpp File Reference

Implementation of hash chains. More...

#include <cmath>
#include <iostream>
#include <memory>
#include <vector>
Include dependency graph for chaining.cpp:

Classes

class  hash_chain
 Chain class with a given modulus. More...
 

Functions

int main ()
 

Detailed Description

Implementation of hash chains.

Author
vasutomar
Krishna Vedala

Function Documentation

◆ main()

int main ( void  )

Main function

Returns
0 always
133  {
134  int c = 0, x = 0, mod = 0, h = 0;
135  std::cout << "Enter the size of Hash Table. = " << std::endl;
136  std::cin >> mod;
137 
138  hash_chain mychain(mod);
139 
140  bool loop = true;
141  while (loop) {
142  std::cout << std::endl;
143  std::cout << "PLEASE CHOOSE -" << std::endl;
144  std::cout << "1. Add element." << std::endl;
145  std::cout << "2. Find element." << std::endl;
146  std::cout << "3. Generate Hash." << std::endl;
147  std::cout << "4. Display Hash table." << std::endl;
148  std::cout << "5. Exit." << std::endl;
149  std::cin >> c;
150  switch (c) {
151  case 1:
152  std::cout << "Enter element to add = " << std::endl;
153  std::cin >> x;
154  h = mychain.hash(x);
155  h = std::abs(h);
156  mychain.add(x, h);
157  break;
158  case 2:
159  std::cout << "Enter element to search = " << std::endl;
160  std::cin >> x;
161  h = mychain.hash(x);
162  mychain.find(x, h);
163  break;
164  case 3:
165  std::cout << "Enter element to generate hash = " << std::endl;
166  std::cin >> x;
167  std::cout << "Hash of " << x << " is = " << mychain.hash(x)
168  << std::endl;
169  break;
170  case 4:
171  mychain.display();
172  break;
173  default:
174  loop = false;
175  break;
176  }
177  std::cout << std::endl;
178  }
179  /*add(1,&head1);
180  add(2,&head1);
181  add(3,&head2);
182  add(5,&head1);
183  display(&head1);
184  display(&head2);*/
185  return 0;
186 }
Chain class with a given modulus.
Definition: chaining.cpp:16
T endl(T... args)
int h(int key)
Definition: hash_search.cpp:45
Here is the call graph for this function: