@S_C_R_E_A_M_E_R

Как удалить элемент массива в Processing?

Как удалить элемент массива в Processing?
Именно из массива "int[] integers = {1, 2, 3};", а не из "IntList integers = new IntList ();"
  • Вопрос задан
  • 217 просмотров
Решения вопроса 1
myjcom
@myjcom
Можно удалить последний элемент

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:

https://www.processing.org/tutorials/arrays/
https://www.processing.org/reference/Array
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы