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