Remove an array element and shift the remaining ones

前端 未结 8 704
灰色年华
灰色年华 2020-11-29 01:09

How do I remove an element of an array and shift the remaining elements down. So, if I have an array,

array[]={1,2,3,4,5} 

and want to del

8条回答
  •  清酒与你
    2020-11-29 01:21

    Just so it be noted: If the requirement to preserve the elements order is relaxed it is much more efficient to replace the element being removed with the last element.

提交回复
热议问题