int[] removeNthElm(int[] array, int nElement)
{
// перемещаем нужный элемент в конец
for(int i = nElement - 1; i < array.length - 1; ++i)
{
// типа swap
int a = array[i];
array[i] = array[i + 1];
array[i + 1] = a;
}
return shorten(array);
}
void draw()
{
int[] a = {1, 2, 3, 4, 5};
a = removeNthElm(a, 1);
printArray(a);
exit();
}
OUT:
[0] 2
[1] 3
[2] 4
[3] 5
The shorten() function decreases an array by one element by removing the last element and returns the shortened array: