vendredi 30 octobre 2020

Dynamic graph using Treap data structure

I am trying to implement Dynamic graph using Treap data structue.

Here is node structure:

    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);
     };          
     

When I want to add neighbouring node to particular node,

  1. I search the node , and then add neighbouring node to search node's vector<int> neighbourNode through updateNode(), in the following way.

searchAddress->neighbourNode.push_back(x);

But my professor says, store address of vector<int> neighbourNode in the node.

  1. Is it going to reduce my TreapNode size ?
  2. How to store address and access it ? I tried this way in TreapNode class but it is giving neighbourNode undefine error.

int* neighbourNodeAddress = neighbourNode.data()

Can anyone help me ?

Aucun commentaire:

Enregistrer un commentaire