简体   繁体   English

碰撞时的哈希表链接。 如何创建指向链表对象的哈希表指针数组?

[英]Hashtable chaining on collisions. How do I create an array of hashtable pointers to linked list objects?

It sounds so simple to do, but I cannot figure out the correct code to implement it.这听起来很简单,但我无法找出实现它的正确代码。

I currently have a doubly linked list class that works well and has been fully tested.我目前有一个双向链表类,它运行良好并且已经过全面测试。 I do not intend to change anything related to this class.我不打算更改与该课程相关的任何内容。

without listing my entire program, within my Hashtable class header file, I have...没有列出我的整个程序,在我的 Hashtable 类头文件中,我有...

#define HASHTABLESIZE 15

class Hashtable {

        public:
                typical public methods listed here
        private:
                Data *hashtable[HASHTABLESIZE];
}

and my cpp file...还有我的cpp文件...

Hashtable::Hashtable() {

        LinkedList list[HASHTABLESIZE];

        for (int i = 0; i < HASHTABLESIZE; i++) {
                this->hashtable[i] = list[i];
        }
}

This is where i am stuck...这就是我被困的地方...

this->hashtable[i] = list[i];

I want an array of pointers to linked list objects.我想要一个指向链表对象的指针数组。 Any help is appreciated.任何帮助表示赞赏。

i think maybe you can use vector in STL.我想也许你可以在 STL 中使用向量。

std::vector<LinkedList> hashtable;
hashtable.reserve(HASHTABLESIZE);
for(int i = 0; i < HASHTABLESIZE; ++i)
        hashtable.push_back(list[i]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM