I need help solving this problem, so if anyone had a similar problem it would help me a lot.
The problem is: How to delete element of array on specific index.
My function:
bool Delete_At_Index(int index)
{
if (index <0 || index>this->numberOfElements)
return false;
for (int i = index+1 ; i < this->numberOfElements; i++)
{
this->arr[i-1] = this->arr[i];
}
this->numberOfElements-- ;
return true;
}
My program contains an Array class so I use this "this".
For example, for the array 11 8 5 3, if I want to delete the element at position 2, the program prints 11 8 3 3. I don't understand why a duplicate of this 3 appears at the end?
Thanks in advance !
Best regards!