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. = ";
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 = ";
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 = ";
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 = ";
166  std::cin >> x;
167  std::cout << "Hash of " << x << " is = " << mychain.hash(x);
168  break;
169  case 4:
170  mychain.display();
171  break;
172  default:
173  loop = false;
174  break;
175  }
176  std::cout << std::endl;
177  }
178  /*add(1,&head1);
179  add(2,&head1);
180  add(3,&head2);
181  add(5,&head1);
182  display(&head1);
183  display(&head2);*/
184  return 0;
185 }
Here is the call graph for this function:
hash_chain
Chain class with a given modulus.
Definition: chaining.cpp:16
std::cout
h
int h(int key)
Definition: hash_search.cpp:45
std::endl
T endl(T... args)
std::cin