How to remove first element from multidimensional array and add new at the end

 

Hello,

i have the following array-Structure.

myarray[level1][level2]

Now i store some values
myarray[0][0]=val0_1 myarray[1][0]=val1_1               myarray[3][0]...etc.
                [1]=val0_2         [1]=val1_2
                [2]=val0_3                                [2]=val1_3
                [3]=val0_4                                [3]=val1_4
  etc.                                          etc.

Now i want to delete the first element and add a new one for a single index and reindex it.
After that the result should be for Example
myarray[1][0]=val1_2 (one index up - the old value val1_1 is deleted)
                [1]=val1_3 (one index up)
                [2]=val1_4 (one index up)
                [3]=val1_5 (this is new)

Is there any prebuild functions to do that?  I want to avoid to make a loop and reorganisate it by hand (the array has up tp 1000 elemens)

Thanks a lot!

 
ReLor2:

Hello,

i have the following array-Structure.

myarray[level1][level2]

Now i store some values
myarray[0][0]=val0_1 myarray[1][0]=val1_1               myarray[3][0]...etc.
                [1]=val0_2         [1]=val1_2
                [2]=val0_3                                [2]=val1_3
                [3]=val0_4                                [3]=val1_4
  etc.                                          etc.

Now i want to delete the first element and add a new one for a single index and reindex it.
After that the result should be for Example
myarray[1][0]=val1_2 (one index up - the old value val1_1 is deleted)
                [1]=val1_3 (one index up)
                [2]=val1_4 (one index up)
                [3]=val1_5 (this is new)

Is there any prebuild functions to do that?  I want to avoid to make a loop and reorganisate it by hand (the array has up tp 1000 elemens)

Thanks a lot!

   int last_index=ArraySize(array)-1;
   array[0]=array[last_index];
   array[last_index]=new_value;  

I propose this solution for one-dimensional array (in case the order is not important for you). 

 
One way to accomplish this, is to use ArrayCopy() to flatten the 2D array into 1D array. Then copy the items you need one by one from the flattened 1D array back into the original 2D array in the required order.

You can take look at RadixSort library in the code base for a similar approach to sort 2D arrays. 

If you have control over the type of array to use from the start, it is easier to use ArrayObj library to define an array of arrays of ArrayInt or ArrayLong.