function to remove the current item

I am having a heck of a time trying to get this function to work right. It does work but not for the first item of the sequence. It actually removes the first and the third item from the sequence. If I have a sequence of 1,2,3 and try to remove the 1, I end up with a sequence that just consists of the number 2. but if i remove the 2 or the 3 it works as intended. If anyone could point me in the right direction i would be very thankful
thanks...

1
2
3
4
5
6
7
8
9
10
11
12
  void sequence::remove_current( )
  {
    size_type i;
   
    assert(is_item()== true);
    
    for (i= current_index; i< used; ++i)
    {
        data[i]= data[i+1];   
        --used;
    }
  }
You have not provided enough context to understand the problem. For starters, why would a type named sequence have any member function names containing current? It seems like you're mixing the idea of a sequence and an iterator.
Im sorry i was trying to avoid posting all my code and was trying to be as specific as possible but you are right that is not enough information my bad.
This is a container class called sequence that stores numbers in an array. the current index is the private member variable that holds the current position of the array. what i was trying to do is remove whatever is in the current position and slide the remaining values to the left. it works for all positions except the first (data[0])
which i cant seem to figure out, but i feel like im close
just got thanks for getting me thinking about it in a more linear way...

1
2
3
4
5
6
7
8
9
10
11
12
13
 void sequence::remove_current( )
  {
    size_type i;
   
    assert(is_item()== true);
    
    for (i= current_index; i< used-1; ++i)
    {
        data[i]= data[i+1];   
       
    }
	 --used;
  }
You could alternatively subtract first then not have to subtract 1 from used each time in the condition.
1
2
--used;
for(i = current_index; i < used; ++i)
Topic archived. No new replies allowed.