我如何实现哈希表,该哈希表在其项中包含单链接列表?

时间:2019-04-08 06:38:02

标签: c++ linked-list hashtable

我写课程的主题是测试系统。其含义是,用户将能够通过其他测试集并编写自己的测试。首先,我需要创建程序的数据类型。

我想出了一个哈希表,该表将存储包含测试主题的测试项目以及单行链接的问题和答案列表。

这是我的数据类型,但我不知道如何将它们彼此连接。

#include <string>

/* One test set */
class Testlist {

    struct node {
        string question;
        string answers[4];
        node *next;
    };

public:

    Testlist();
    /* num - marker of the question or one of the answers */
    void Addquestion(string name, int num); 

};

class Test: public Testlist {
    /* maximum number of tests */
    static const int tablesize = 100;

    /* Member of the hash-table */
    struct item {
        string testname; /* Test name */
        Testlist *set; /* Set of questions and answers to them */
        Test *next;
    };

    /* Hash table of tests */
    item *testtable[NHASH];
public:

    Test();
    unsigned int hash(string key);
    void AddItem(string name, int create);

};

在这种情况下,如何使用单链表的下一个指针?请说明我如何正确实施。

0 个答案:

没有答案