0 Views
0 Downloads
0 Favorites
Arrays
ÿþ/**/

#include <SRC\Service\Arrays.mqh>

/****************************************************************

Examples of Arrays class usage.

/****************************************************************/

void OnStart()

  {

   int a[],asrc[]= {1,2,3,4};

   int b[],bsrc[]= {5,6,7};

   ArrayCopy(a,asrc);

   ArrayCopy(b,bsrc);

   /**/

   Arrays arrays;

   arrays.Insert(a,b,0);         //insert array in array

   arrays.Insert(0,a,3);         //insert element in array

   arrays.Add(8,a);              //add element to array

   double sum=arrays.Sum(a);     

   double avg=arrays.Average(a);

   double max=arrays.Max(a);

   int findwhat=2;

   int findindex=arrays.Find(findwhat,a);

   int findrev=arrays.FindReverse(findwhat,a);

   int size=ArraySize(a);

   /**/

   string print=StringFormat("size:%d, sum:%g, avg:%g, max:%g, '%d' found in pos:%d, '%d' found rev in pos:%d",

                             size,sum,avg,max,findwhat,findindex,findwhat,findrev);

   short printcodes[];

   arrays.StringToCodes(print,printcodes); //convert string to array of char codes

   Print(print);

   ArrayPrint(a);

   ArrayPrint(printcodes);

  }

/****************************************************************

Output:

/**

   size:9, sum:36, avg:4, '2' found in pos:5, '2' found rev in pos:3

   5 6 7 0 1 2 3 4 8

   [ 0] 115 105 122 101  58  57  44  32 115 117 109  58  51  54  44  32  97 118 103  58  52  44  32  39  50  39  32 102 111 117 110 100  32

   [33] 105 110  32 112 111 115  58  53  44  32  39  50  39  32 102 111 117 110 100  32 114 101 118  32 105 110  32 112 111 115  58  51

/**/

Comments