:
delete [] array[j+1];
, 'array [j + 1]'. 'array [j + 1]' :
array[i] = new element;
, , . :
delete array[j+1];
, , , . , , , , "", "" , A, B, C, D E.
removeelements(), "array" :
array[0] -> A
array[1] -> B
array[2] -> C
array[3] -> D
array[4] -> E
'numofelements' 5.
removeelements() , , 1, :
for(j=1;j<3;j++){
array[j] = array[j+1];
}
, [2] ' ' array [1] '' array [3] ', ' array [2]. "array" :
array[0] -> A
array[1] -> C
array[2] -> D
array[3] -> D
array[4] -> E
'j' 3, 'delete array [j + 1]' , 'array [4]', 'E'.
'numofelements' 4.
, , 3. "numofelements" 4, :
for(j=3;j<2;j++){
array[j] = array[j+1];
}
'j' 3. , 2, , "array" .
'j' 3 ', delete [j + 1]' 'array [4]', E. , E , , .
, 3, , , 4. :
for(j=4;j<1;j++){
array[j] = array[j+1];
}
'j' 4 . 'delete array [j + 1]' , 'array [5]', "array" .
As others have shown, the best way to handle this is to use std :: vector. However, the way to structure your code even std :: vector will not give you the desired results, because as soon as you remove one element from the "array", the indices of all subsequent ones will change, which means that the remaining indices in the 'removeelist' will no longer be correct .
I suggest that any changes you make, you manually execute the code, as I already above, tracking the contents of the array and the corresponding variables so that you can understand exactly what your code is doing.