Clearing an array of defined element(s) - page 6

 
TheXpert:
One has 42 products, one has 6, one has 30. I'm afraid to imagine what an asshole there is inside with questions and answers like that
+1000500
 
Реter Konow:

Sorry. It looks like the lines need to be reversed:

Have you tried a run? Even without a run, you can tell that it's not a problem to get out of the array when copying.

if(deleted)Arr[a1] = Arr[a1 + deleted];
 
Sergey Chalyshev:
+1000500

The circus has already left.

 
Dmitry Fedoseev:

We have to get the basics right.

This is the main point,

you need the right (strategy) approach to solving the problem.

 
Dmitry Fedoseev:

The circus has already left.

Gone where? Like a circus?

I don't think he's going anywhere, and if he does, it won't be for long and he'll be back for sure.)

 
Konstantin Nikitin:

Have you tried a run? Even without a run, you can tell that it won't be a problem to get out of the array when copying.

Just a second. Checking my solution. Just jotting down what came into my head. I'll check it out.

 
//+------------------------------------------------------------------+
//|                                             Erase and Resize.mq5 |
//|                                                      Peter Konow |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Peter Konow"
#property link      "https://www.mql5.com"
#property version   "1.00"
//--------------------------------------------------------------------
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   int Arr[20] = {1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2};
   ulong q1 = GetMicrosecondCount(); 
   //--------------------------------
   int deleted = 0,q = 0;
   //-------------- 
   for(int a1 = 0; a1 < ArraySize(Arr); a1++)
     {
      if(deleted)Arr[q] = Arr[q + deleted];
      if(Arr[q] == 3){deleted++; q--;}
      q++;
     }
   //--------------
   ulong q2 = GetMicrosecondCount(); 
   //--------------------------------
   //ArrayResize(Arr, ArraySize(Arr) - deleted);    
   //--------------------------------
   Print(Arr[0],",",Arr[1],",",Arr[2],",",Arr[3],",",Arr[4],",",Arr[5],",",Arr[6],",",Arr[7],",",Arr[8],",",Arr[9],
        ",",Arr[10],",",Arr[11],",",Arr[12],",",Arr[13],",",Arr[14],",",Arr[15],",",Arr[16],",",Arr[17],",",Arr[18],",",Arr[19]);
   Print("Array new size  ",ArraySize(Arr),"  Тime of operation  ",q2-q1,"  deleted  ",deleted);
   //--------------------------------  
  }
//+------------------------------------------------------------------+
2018.11.13 13:49:15.813 Erase and Resize (USDJPY,H1)    Array new size  20  Тime of operation  1  deleted  6
2018.11.13 13:49:15.813 Erase and Resize (USDJPY,H1)    1,2,1,2,1,2,1,2,1,2,1,2,1,2,3,1,2,3,1,2  <--------------последние шесть цифр остались неизмененными, потому что не сделал АrrayResize;
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
Ask questions on technical analysis, discuss trading systems and improve your MQL5 programming skills to develop your own trading strategies. Communicate and share your experience with traders from anywhere in the world, answer questions and help beginners — MQL5.community is developing along with you. How to avoid opening of new order Hello...
 

The solution removes all the triples, but does not remove the digits at the end, because these digits should disappear when ArrayResize.

In other words, the last digits, are the ones that are not part of the modified array. I just didn't doan ArrayResize

 
Реter Konow:

What's there to talk about?

Print(Arr[0],",",Arr[1],",",Arr[2],",",Arr[3],",",Arr[4],",",Arr[5],",",Arr[6],",",Arr[7],",",Arr[8],",",Arr[9],
        ",",Arr[10],",",Arr[11],",",Arr[12],",",Arr[13],",",Arr[14],",",Arr[15],",",Arr[16],",",Arr[17],",",Arr[18],",",Arr[19]);
Perhaps how is it even more refined to smear the forum with shitcod.
 
Sergey Dzyublik:

What's there to talk about?

Perhaps how it would be even more refined to smear the forum with shitcod.

Do you have a quicker solution?

Man, how I love to put down people fixated on the form rather than the content. It's a pleasure.)

Reason: