Remove an array element and shift the remaining ones

前端 未结 8 734
灰色年华
灰色年华 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:40

    Programming Hub randomly provided a code snippet which in fact does reduce the length of an array

    for (i = position_to_remove; i < length_of_array; ++i) {
            inputarray[i] = inputarray[i + 1];
    }
    

    Not sure if it's behaviour that was added only later. It does the trick though.

提交回复
热议问题