24 Week Project One--hashing storage and lookup

Source: Internet
Author: User

Hashing


Instance:

#include <iostream>using namespace Std;int searchhash (int h[], int l, int key); void Inserthash (int h[], int l, int d    ATA); int main () {const int hashlength = 13;//hash table length int hashtable[hashlength]={0};    int m, n;        Create hash for (int i = 0; i < 6; i++) {cin>>n;    Inserthash (hashTable, Hashlength, N);    } cin>>m;    int result = Searchhash (Hashtable,hashlength, M);    if (Result! =-1) cout<< "is already found in the array, the position is:" << result<<endl;    else cout<< "No this original" <<endl; return 0;}    int Searchhash (int h[], int l, int key) {///hash function int hashaddress = key% L; Specifies that the hashadrress corresponding value exists but is not a critical value, and the open addressing method is used to resolve while (h[hashaddress]! = 0 && h[hashaddress]! = key) {HASHADDR    ESS = (++hashaddress)% L;    }//Check found the open unit, indicating that the search failed if (h[hashaddress] = = 0) return-1; return hashaddress;}    Data insert hash table void Inserthash (int h[], int l, int data) {///hash function int hashaddress = data% L; If the key is storedIn, then the conflict must be resolved while (h[hashaddress]! = 0) {//hashaddress = (++hashaddress)% l is found with open addressing method; }//Store data in dictionary h[hashaddress] = data;}
Operation Result:





24 Week Project One--hashing storage and lookup

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.