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
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;
157 break;
158 case 2:
159 std::cout << "Enter element to search = " << std::endl;
160 std::cin >> x;
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
180
181
182
183
184
185 return 0;
186}
Chain class with a given modulus.