Double hashing

Time limit: 5000ms
Memory limit: 256mb

Description:
This program is to insert N key-record pair into hash table using double hashing and search some keys.
First insert some key-record pairs into the table, then answer some queries. Function implementation details are written in the comments preceding the function definition. Please read them carefully.
For the query key, if the query key is not in the hash table, output -1, otherwise output the corresponding the index in the hashTable.

-------------------------Copy the following code, complete it and submit-------------------------


/*
I, <Your Full Name>, am submitting the assignment for
an individual project.
I declare that the assignment here submitted is original except for
source material explicitly acknowledged, the piece of work, or a part
of the piece of work has not been submitted for more than one purpose
(i.e. to satisfy the requirements in two different courses) without
declaration. I also acknowledge that I am aware of University policy
and regulations on honesty in academic work, and of the disciplinary
guidelines and procedures applicable to breaches of such policy and
regulations, as contained in the University website
http://www.cuhk.edu.hk/policy/academichonesty/.
It is also understood that assignments without a properly signed
declaration by the student concerned will not be graded by the
teacher(s).
*/

#include <stdio.h>
#include <stdlib.h>

const int hashTableSize = 29989;

struct Node {
    int key;
    int record;
};

/**
 * @brief: create an node
 * @param: 1. key   2. record
 * @return: address of the node
 * @usage: struct Node* newNode = CreateNode(yourKey, yourRecord)
 */
struct Node* CreateNode(int key, int record) {
    struct Node* newNode = (struct Node*) malloc(sizeof(struct Node));
    newNode->key = key;
    newNode->record = record;
    return newNode;
}

/**
 * @brief: get the hash value of a key
 * @param: 1. key 
 * @return: hash value
 * @usage: int hashValue = HashFunction1(yourKey)
 */
int HashFunction1(int key) {
    return key % hashTableSize;
}

/**
 * @brief: get the hash value of a key
 * @param: 1. key 
 * @return: hash value
 * @usage: int hashValue = HashFunction2(yourKey)
 */
int HashFunction2(int key) {
    return 1 + key % 1069;
}

/**
 * @brief: insert an node into a hashTable. If key has existed, modify its record with new one
 * @param: 1. hashTable   2. key  3. record
 * @return: void
 * @usage: InsertHashTable(yourHashTable, yourKey, yourRecord)
 */
void InsertHashTable(struct Node* hashTable[], int key, int record) {
    // WRITE YOUR CODE HERE
    // DO NOT MODIFY THE OTHER CODE
}

/**
 * @brief: search an node in a hashTable. 
 * @param: 1. hashTable   2. key 
 * @return: If key does not exist, return -1. Or return the index in the hashTable.
 * @example: If search key 2 is in the hashTable[1], Then you should return 1.
 * @usage: int index = SearchHashTable(yourHashTable, yourKey)
 */
int SearchHashTable(struct Node* hashTable[], int key) {
    // WRITE YOUR CODE HERE
    // DO NOT MODIFY THE OTHER CODE
}


int main() {
    struct Node* hashTable[hashTableSize];
    for (int i = 0; i < hashTableSize; i++) {
        hashTable[i] = NULL;
    }

    int insertNum, searchNum;
    int key, record;
    scanf("%d", &insertNum);
    for (int i = 0; i < insertNum; i++) {
        scanf("%d%d", &key, &record);
        InsertHashTable(hashTable, key, record);
    }

    scanf("%d", &searchNum);
    for (int i = 0; i < searchNum; i++) {
        scanf("%d", &key);
        int index = SearchHashTable(hashTable, key);
        printf("%d\n", index);
    }
    printf("\n");
}

-------------------------------------------End of Code-------------------------------------------

Input:
First line: num of insertion pairs (named insertNum)
next insertNum lines: two integers which are key and record
next line: num of search operation (named searchNum)
next searchNum lines: one integer which is search key

Output:
searchNum lines of search result: If no key is found output -1. If the key is found, print the corresponding the index in the hashTable.

Sample Input 1:
5
5 538
5 120
3 250
1 304
5 359
6
4
4
5
2
5
3

Sample Output 1:
-1
-1
5
-1
5
3

Submit