How do I remove an element from an array (one-dimensional two-dimensional)? - page 2

 
Seric29:

how the function works

There is no description in the handbook where to read about it?

Do you read this thread? Admin replied - description coming soon

 
Seric29:

I don't reduce the size of the array but remove an element from it...

void  ArrayFill( 
   void&  array[],       // массив 
   int    start,         // индекс начального элемента 
   int    count,         // количество элементов 
   void   value          // значение, которым заполняется массив 
   );

Would that not work?

 
Ilya Malev:

The comrade has written: one-dimensional and two-dimensional. Your function doesn't work with two-dimensional. Show me how to make a function with the same name work for both :)

I didn't see anything about two-dimensional. But the two-dimensional in itself also copied, only slightly different values from which index to write to array pickup and from which index to read from the source. In principle, the problem can be solved for 3-4 dimensional arrays allowed in mql

 
Seric29:

I'm not reducing the size of the array, but I'm removing an element from it, which are different things. I understand that your function deleted value1.13612, it is specified in the linedellArrayElement(3, array); i.e. the 3rd element is removed from the array, didn't it? What is the speed of such experiments, how much do they load the program?

But if the condition is

Forum on trading, automated trading systems and strategy testing

How do I remove an element from an array (one-dimensional two-dimensional)?

Seric29, 2018.12.21 23:50

How do you remove an element from an array? Do I need to know the number of elements stored in it?

then naturally the size of the array should be reduced. Isn't it so?

Yes, for the example it was the 3rd element of the array that was deleted. Speeds and some body parts are measured in other branches. In this case the speed is quite normal. You have to do several runs of several hundred deletions for approximate speed values. Why would I want to do that?

 
https://www.mql5.com/ru/forum/289594
Очистка массива от заданного (ых) элементов
Очистка массива от заданного (ых) элементов
  • 2018.11.12
  • www.mql5.com
Есть массив содержащий набор данных по типу 1,2,3,6,9,5,6,3,25,6,8,7,4 нужно удалить например значения 3 и на выходе получить тот же массив без 3 и...
 
Alexey Viktorov:

I didn't see anything about the two-dimensional one. But the two-dimensional is also copied in itself, only slightly different values from which index to write to the array and which index to read from the source. In principle, the problem can be solved for 3-4 dimensional arrays allowed in mql

I'm guessing it's solvable in principle. Except that it doesn't seem to be solvable for a function with the same name.

 
Ilya Malev:

I'm guessing it's solvable in principle. Except that it doesn't seem to be solvable for a function with the same name.

Why? Do it as an elementary class.

Something like

class A
{
 void DellArrElement(int i, double &arr[]);
 void DellArrElement(int i, double &arr[][]);
};

void A::DellArrElement(int i, double &arr[])
 {
  // тело функции для одномерного массива
 };

void A::DellArrElement(int i, double &arr[][])
 {
  // тело функции для двухмерного массива
 };

It was written "on the spot", so apologize for possible inaccuracies.

 

If the order of the elements in the array is not important, it is done quickly enough:

#define  ARRAY_RESERVE_SIZE    1000

template<typename T>
void DeleteElementFromArray(T &array[], int elementToDelete)
{  
   int arraySize = ArraySize(array);
   if (elementToDelete < 0 || elementToDelete >= arraySize)
      return;
      
   array[elementToDelete] = array[arraySize - 1];
   ArrayResize(array, arraySize - 1, ARRAY_RESERVE_SIZE);
}

This is for a one-dimensional array. Two-dimensional and larger arrays are actually one-dimensional arrays. A one-dimensional array can logically be represented as an N-dimensional array. That is, in fact, a one-dimensional array is always sufficient.

 
Alexey Viktorov:

Why? Do it as an elementary class.

Something like...

It's written on the fly, so excuse me for any inaccuracies.

Have you tried to compile it?

 
Ilya Malev:

Have you tried compiling this?

They haven't figured out how to make the compiler directly on the forum site yet.

Forum on trading, automated trading systems and strategy testing

How to remove element from array (one-dimensional two-dimensional)?

Alexey Viktorov, 2018.12.22 21:25

Why? Do it as an elementary class.

Something like.

class A
{
 void DellArrElement(int i, double &arr[]);
 void DellArrElement(int i, double &arr[][]);
};

void A::DellArrElement(int i, double &arr[])
 {
  // тело функции для одномерного массива
 };

void A::DellArrElement(int i, double &arr[][])
 {
  // тело функции для двухмерного массива
 };

Written "by hand", so apologize for possible inaccuracies.


Reason: