Array shifting elements

Hello,

Please help me how to shift array elements
i need to delete 1 element of the array and shift the other elements

ex. code:

1
2
3
4
5
6
for (int i=0; i < N; ++i)
{
L[i].Name = obj.Name;
L[i].Price = obj.Price;
N++;
}


let's say i need to delete L[10] and i need to shift the other elements, how to do that ?

Thanks :)
Last edited on
You probably meant
1
2
3
4
5
for (int i=0; i < NumberOfBooks; ++i)
{
    list[i].Name = obj.Name;
    list[i].Price = obj.Price;
}


That apart, what is the data type of list? A STL container or an user-defined container? It sure isn't the std::list. Whatever type list is, you should be looking at using a member function ::erase which usually takes an iterator.
Given the homework difficulty index for this question, it is likely that 'list' is just the name OP has given his array.

It will help a lot to get out a piece of paper and a pencil (with an eraser), draw yourself an array (a bunch of boxes all in a line) full of values (unique numbers in the boxes, like 1,2,3,...) and erase the 2.

Now figure out how to move all the numbers (3,4,...) left one box, without losing any of the numbers along the way.

Hope this helps.
@OxBADC0DE its a pointer of class

@Duoas thank you, i'll try that now
Topic archived. No new replies allowed.