Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 144
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I'm already confused)
You have an array:
What should the function eventually return and why? The number of matches for each number, or a specific maximum number, or ... Did I write something, but it must be wrong, and wrong?
I don't know how to explain...
We see an array:1, 2, 3, 1, 2, 1, 2, 2, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3,
We mark identical numbers with the same colour (if there is only one number, there is no duplicate for it - it is not needed):
1, 2, 3, 1, 2, 1 , 2 , 2, 1, 1, 1, 3, 3, 3 , 3 , 3 , 3 , 3, 3 , 3, 3,3
Count the number of numbers with different colours: 3 - this is the result.
You have checked the old code. Double-check it.
I don't know how to explain...
We see an array:1, 2, 3, 1, 2, 1, 2, 2, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3,
We mark identical numbers with the same colour (if there is only one number, there is no double for it - it is not needed):
1, 2, 3, 1, 2, 1 , 2 , 2, 1, 1, 1, 3 , 3, 3 , 3 , 3 , 3, 3 , 3 , 3, 3,3
Count the number of numbers with different colours: 3 - this is the result.
Maybe)
{
int Arr[]={1, 2, 3, 1, 2, 1, 2, 2, 1, 3, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3};
Comment( GetM(Arr) );
}
int GetM(int &Mas[])
{
int MasTemp[][2]; // Временный массив
int c=0,t=0;
ArraySort(Mas);
int ArrSize= ArraySize(Mas);
for(int i=0; i<ArrSize; i++) {
for(int x=i; x<ArrSize; x++) {
if(Mas[i]==Mas[ArrayMinimum(Mas,WHOLE_ARRAY,x)]) {
c++;
}
}
if(c>0) {
t++;
ArrayResize(MasTemp,t);
MasTemp[t-1][0]= c;
MasTemp[t-1][1]= Mas[i];
}
c=0;
}
int ArrRange=ArrayRange(MasTemp,0);
if(ArrRange>0) {
ArraySort(MasTemp);
// Comment("Цифра: ",MasTemp[ArrRange-1][1],", Количество: ",MasTemp[ArrRange-1][0]);
return( MasTemp[ArrRange-1][1] );
}
return(-1);
}
There ... I'm a weirdo... I thought it came from there, but it came from someplace else.
template <typename T>
int Strange( const T &InArray[], const int Repeat = 2 )
{
int Res = 0;
T Array[];
const int Size = ArraySize(InArray);
if ((ArrayCopy(Array, InArray) == Size) && ArraySort(Array))
{
int Tmp = 1;
for (int i = 1; i < Size; i++, Tmp++)
if (Array[i - 1] != Array[i]) // если будут структуры, то есть более универсальная запись
{
if (Tmp >= Repeat)
Res++;
Tmp = 0;
}
if (Tmp >= Repeat)
Res++;
}
return(Res);
}
void OnStart()
{
int Array[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
for (int i = 1; i <= 4; i++)
Print(Strange(Array, i));
}
Summarised
Maybe)
Summarised by
This is interesting
With this notation, an Array can not only be a numeric type, but any simple structure.
Another thing is that ArraySort for structures, of course, does not work.
With this notation, an Array can not only be a numeric type, but any simple structure.
Another thing is that ArraySort for structures, of course, does not work.
Exactly... But structures are usually very complex. And they still have to be sorted...
Complex are containing objects (strings, for example).
MqlTick is a simple structure.
MqlTradeRequest - complex.
ArraySort can easily be written for simple structures.