dimanche 20 mars 2022

How to add a value at some list[x][y] in C++?

I am trying to add some value at cost[x][y] and the list must be a pointer type. I declared the list like this:

list<int>* cost = new list<int>[V]; // V being user input

And here I'm trying to add the value "c" at the place of cost[x][y]. How am I supposed to add that .When I try to use iterator as below it says

  1. "Debug Assertion Failed"

  2. "Unable to increment end point iterator"

The Code:

    void addCost(int x, int y, int c) // adds cost in cost[x][y] and cost[y][x] indicies
    {
        auto it = cost[x].begin();
        advance(it, y);
        *it = c;
    }

Aucun commentaire:

Enregistrer un commentaire