mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
add function definitions
This commit is contained in:
parent
3db7cefdd9
commit
1e261cb8fe
@ -16,7 +16,10 @@ int counter = 1;
|
|||||||
int h(int key) {
|
int h(int key) {
|
||||||
return key % HASHMAX;
|
return key % HASHMAX;
|
||||||
}
|
}
|
||||||
void create_list(int key) {
|
// 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.
|
||||||
|
void create_list(int key) { // Construct hash table
|
||||||
link p, n;
|
link p, n;
|
||||||
int index;
|
int index;
|
||||||
n = (link) malloc(sizeof(node));
|
n = (link) malloc(sizeof(node));
|
||||||
@ -30,7 +33,7 @@ void create_list(int key) {
|
|||||||
} else {
|
} else {
|
||||||
hashtab[index].next = n; }
|
hashtab[index].next = n; }
|
||||||
}
|
}
|
||||||
int hash_search(int key) {
|
int hash_search(int key) { // Hash lookup function
|
||||||
link pointer;
|
link pointer;
|
||||||
int index;
|
int index;
|
||||||
counter = 0;
|
counter = 0;
|
||||||
@ -55,11 +58,11 @@ int main() {
|
|||||||
for (i = 0; i < HASHMAX; i++)
|
for (i = 0; i < HASHMAX; i++)
|
||||||
scanf("%d", & data[i]);
|
scanf("%d", & data[i]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
while (index < MAX) {
|
while (index < MAX) { // Construct hash table
|
||||||
create_list(data[index]);
|
create_list(data[index]);
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
for (i = 0; i < HASHMAX; i++) {
|
for (i = 0; i < HASHMAX; i++) { // Output hash table
|
||||||
printf("hashtab [%d]", i);
|
printf("hashtab [%d]", i);
|
||||||
printf("n");
|
printf("n");
|
||||||
p = hashtab[i].next;
|
p = hashtab[i].next;
|
||||||
|
Loading…
Reference in New Issue
Block a user