jeudi 27 octobre 2022

Building red-black tree with vector of lists in C++

 vector<list<Nodo<string>*>> lista;

i have this vector of lists and I'm trying to write a method to insert elements into it

  template <typename T> void HashRBT<T>:: riempimento()
{
     for(auto &it:vett_dati) 
    {   int key=it.first;
        string value=(it.second);
        int id=hashFunctionDivsion(key); 
        Nodo<T> *x=rb->searchNodo(rb->getRoot(),id);
        if(x==rb->getNillT()) 
        {
         rb->insertNodoRB(id,value);
        }

      else {  
        lista.resize(getDim());
        Nodo<T> *y= new Nodo<T>(id,value);
       lista.at(id).push_front(y); //inserimento in testa
      }
    }
    Print_Lista(); 
}

now in the else block is where I go to insert the elements in this vector of lists but I don't understand why if I comment the resize statement this doesn't work and I get an error like this: vector :: _ M_range_check. I would like someone to explain to me what happens in memory? what am i allocating with that resize?

Aucun commentaire:

Enregistrer un commentaire