我正在尝试使用 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);
};
当我想将相邻节点添加到特定节点时,
- 我搜索节点,然后
vector<int> neighbourNode
通过updateNode()
以下方式将相邻节点添加到搜索节点。
searchAddress->neighbourNode.push_back(x);
但是我的教授说,vector<int> neighbourNode
在节点中存储地址。
- 它会减少我的 TreapNode 大小吗?
- 如何存储地址和访问它?我在 TreapNode 类中尝试过这种方式,但它给出了
neighbourNode
undefine 错误。
int* neighbourNodeAddress = neighbourNode.data()
谁能帮我 ?