Thanks for the answer. It works now!
Raj
On 12 fév, 01:02, tonydee <(EMail Removed)> wrote:
> On Feb 12, 1:39*pm, Raj <(EMail Removed)> wrote:
>
> > I have a 2D vector declared as vector<vector <uint> > solution(m,
> > vector<uint>n). I have initialized this vector with values. Now I want
> > to insert an element in the (i,j) position. I am trying to do
> > solution[i].insert(j, 1, value), but this gives me the error 'no
> > matching function for call to 'std::vector<unsigned int,
> > std::allocator<unsigned int> >::insert(uint&, int, int)'
>
> > How do I get this done?
>
> > Thanks,
> > Raj
>
> Given
> * * iterator insert(iterator pos, const T& x)
>
> Try
> * * solution[i].insert(solution[i].begin() + j, value)
>
> I trust you realise, in psuedocode:
> * * *{1, 2, 4}.insert(begin() + 2, 3) == {1, 2, 3, 4}
> whereas
> * * *{1, 2, 4}[2] = 3 == {1, 2, 3}.
> The former is typically slower, as elements after the insertion point
> need to be "moved over" to make space, and sometimes the array may
> need to be resized and all elements copied. *Only if this proves a
> performance problem with your particular data set, you may want to
> consider using a std::list<>....
>
> Cheers,
> Tony
