TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Hash Search Algorithm - Best Time Complexity Ω(1) More...
#include <cstdlib>
#include <iostream>
Go to the source code of this file.
Classes | |
struct | list |
Macros | |
#define | MAX 6 |
Determines how much data. | |
#define | HASHMAX 5 |
Determines the length of the hash table. | |
Typedefs | |
typedef struct list | node |
typedef struct list * | link |
pointer to nodes | |
Functions | |
int | h (int key) |
void | create_list (int key) |
int | hash_search (int key, int *counter) |
int | main () |
Variables | |
int | data [MAX] = {1, 10, 15, 5, 8, 7} |
test data | |
node | hashtab [HASHMAX] |
array of nodes | |
Hash Search Algorithm - Best Time Complexity Ω(1)
In this algorithm, we use the method of division and reservation remainder to construct the hash function, and use the method of chain address to solve the conflict, that is, we link a chain list after the data, and store all the records whose keywords are synonyms in the same linear chain list.
Definition in file hash_search.cpp.
#define HASHMAX 5 |
Determines the length of the hash table.
Definition at line 22 of file hash_search.cpp.
#define MAX 6 |
Determines how much data.
Definition at line 21 of file hash_search.cpp.
typedef struct list node |
a one-way linked list define node as one item list
void create_list | ( | int | key | ) |
The same after the remainder will be added after the same hash header To avoid conflict, zipper method is used Insert elements into the linked list in the header
[in] | key | key to add to list |
n
never gets freed. Definition at line 55 of file hash_search.cpp.
int h | ( | int | key | ) |
Mode of hash detection : Division method
[in] | key | to hash |
key
Definition at line 45 of file hash_search.cpp.
int hash_search | ( | int | key, |
int * | counter ) |
Input the key to be searched, and get the hash header position through the H (int key) function, then one-dimensional linear search. If found
Definition at line 76 of file hash_search.cpp.
int main | ( | void | ) |
main function
Definition at line 99 of file hash_search.cpp.
int data[MAX] = {1, 10, 15, 5, 8, 7} |
array of nodes
Definition at line 35 of file hash_search.cpp.