0

我正在尝试使用 Treap 数据结构实现动态图。

这是节点结构:

    class TreapNode
    {
        public:
                int key;
                int priority;
                TreapNode* left, *right;
                vector<int> neighbourNode;
                
                TreapNode(int key)
                {
                    this->priority = 0;
                    this->key = key;
                    this->left  = nullptr;
                    this->right = nullptr;
                }
                
                TreapNode()
                {}
                
                TreapNode* addNode(TreapNode*&,int);
                void updateNode(TreapNode*&,int,int);
     };          
     

当我想将相邻节点添加到特定节点时,

  1. 我搜索节点,然后 vector<int> neighbourNode通过updateNode()以下方式将相邻节点添加到搜索节点。

searchAddress->neighbourNode.push_back(x);

但是我的教授说,vector<int> neighbourNode在节点中存储地址。

  1. 它会减少我的 TreapNode 大小吗?
  2. 如何存储地址和访问它?我在 TreapNode 类中尝试过这种方式,但它给出了neighbourNodeundefine 错误。

int* neighbourNodeAddress = neighbourNode.data()

谁能帮我 ?

4

0 回答 0