C + + Implementation Hash_set

Source: Internet
Author: User

Header file:

#include <iostream>using namespace Std;template<class hash_type>class hash_set{private:hash_type array[ 100000];int Hash_fun (hash_type original);p ublic:hash_set ();//constructor void Insert (Hash_type value);//Insert an element void erase ( Hash_type target);//delete an element bool contain (hash_type query);//Determine whether an element is in the collection};
class function implementations:

#include "hash_set.h" template<class hash_type> #define MAX_LENGTH 100000int Hash_set
To test the main function:

#include <iostream> #include "hash_set.cpp" int main () {hash_set<int> Hs;while (True) {cout << "Begin Test:\ninput 1 to Insert;2 to find; 3 to delete\n "; Int. Flag;int value;cin >> flag;switch (flag) {case 1:cout << ' input the value to insert:\n '; CIN >> Value;hs.insert (value); Break;case 2:cout << "input the value to find:\n"; Cin >> Value;if (hs.contain (value)) cout << "yes\n"; else cout << "no\n"; break;case 3:cout << "input the value to delete\n"; Cin >> Valu E;hs.erase (value); Break;default:cout << "Input error.\n"; break;}} return 0;}



C + + Implementation Hash_set

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.