小编Dar*_*i99的帖子

Unordered_Map查找时间

C++库中的内置映射和集合(包括unordered_map和multimap)要求find函数(用于查找特定元素)使用迭代器来遍历元素.C++参考站点声称使用这些数据结构查找元素平均需要时间,就像常规哈希表一样.但是,迭代器是否必须遍历整个列表,在找到元素之前平均得到这个O(n)时间?

performance unordered-map hashtable hashmap multimap

3
推荐指数
1
解决办法
5210
查看次数

在类中创建动态数组(C++)

我想用数组实现一个类.如果数组的大小被破坏,我会调用resize()函数.但是我似乎无法将动态数组编码为数据成员.有人可以指导我如何解决这个问题吗?

这是我到目前为止所得到的:

class ArrayList
{
        public:
        ArrayList()
        {
                array[ARR_SIZE] = {0};
                space = 0;
                size = ARR_SIZE;
        }
        void insert(int place, int value)
        {
                if (place >= size)
                        cout << "Sorry, that index is not accessible" << endl;
                else
                {
                        array[place] = value;
                        space++;

                if(space == size)
                        allocate();
                }
        }
        void remove(int place)
        {
                if(place >= size)
                        cout << "Sorry, that index is not accessible" << endl;
                else
                {
                        array[place] = NULL;
                        space--;
                }

        }
        void allocate()
        {
                int* array …
Run Code Online (Sandbox Code Playgroud)

c++ class arraylist

0
推荐指数
1
解决办法
1139
查看次数